我怎么可以添加自定义URL参数,一个MVC RedirectToAction [英] How can I add custom URL parameters to a MVC RedirectToAction
本文介绍了我怎么可以添加自定义URL参数,一个MVC RedirectToAction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在有一个简单的MVC RedirectToAction动作:
返回RedirectToAction(编辑,客户,新{ID = iNewId});
这重定向到通知客户/编辑/ 1
不过,我想一些自定义的值附加到会习惯由JavaScript的网址,网址返回如通知客户/编辑/ 1#TAB1
什么是这样做的最好的方法?
解决方案
routes.MapRoute(WithTarget,{控制器} / {行动} / {ID}#{}目标);
和
RedirectToAction(编辑,客户,新{ID = iNewId,目标=TAB1});
或
RedirectToRoute(WithTarget,新{控制器=客户,行动=编辑,ID = iNewId,目标=TAB1});
但请记住,片段从来没有从客户端发送到Web服务器,所以没有办法读取其在控制器的动作值。
I currently have a simple MVC RedirectToAction action:
return RedirectToAction("Edit", "Customers", new {Id = iNewId});
which redirects to Cutomers/Edit/1
However I'd like to append some custom values to the URL which will get used by javascript, returning URLs such as Cutomers/Edit/1#Tab1
What is the best method of doing this?
解决方案
routes.MapRoute("WithTarget", "{controller}/{action}/{id}#{target}");
and
RedirectToAction("Edit", "Customers", new { id = iNewId, target = "Tab1" });
or
RedirectToRoute("WithTarget", new { controller = "Customers", action = "Edit", id = iNewId, target = "Tab1" });
But remember that the fragment is never sent from the client to the web server, so there's no way to read its value in a controller action.
这篇关于我怎么可以添加自定义URL参数,一个MVC RedirectToAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文