问题
I am still learning to work with asp.net and I am trying to redirect to an Edit action in a controller from another controller, but I can’t find out how to make it work. this is what I have
return RedirectToAction("Edit", "Worker");
or
return RedirectToAction("Edit", "Worker", 25);
I need it to be something like this: http://localhost:xxxxx/Worker/Edit/25
回答1:
You can do the following
return RedirectToAction("Edit", "Worker", new { id = 25});
回答2:
You can pass the route value parameters as Route value
Object using the new
Keyword...as
return RedirectToAction("Edit", "Worker", new { id = 25});
And if you want to add multiple values you can go like adding the values separated by a comma ,
return RedirectToAction("Edit", "Worker", new { id = 25,name ="tushar"});
Or you can create a RouteValueDictionary
, add the items and send the object of it at once as
RouteValueDictionary _routValueDict = new RouteValueDictionary();
_routValueDict.Add("param1", param1);
_routValueDict.Add("param2", param2);
No pass the object like :
return RedirectToAction("Edit", "Worker", _routValueDict );
来源:https://stackoverflow.com/questions/30429350/redirecting-in-asp-net-5