Redirecting in asp.net 5

耗尽温柔 提交于 2019-12-11 11:19:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!