MVC RedirectToAction is not working properly

2019-08-19 02:23发布

问题:

In one of my controllers, I do have a return that looks like this:

return RedirectToAction("AdministerFiles/ViewDataFiles?catid=14");

but when it renders the result to the browser the string becomes this one:

AdministerFiles/AdministerFiles/ViewDataFiles%3fcatid%3d14

how can I solve this ? thanks .

回答1:

You just need the action as the parameter (along with the route data):

return RedirectToAction("ViewDataFiles", new { catid = 14 });

If you want to specify the controller as well (it defaults to the current controller), then you can do it like this:

return RedirectToAction("ViewDataFiles", "AdministerFiles", new { catid = 14 });