在执行重定向操作后,MVC中是否有指定浏览器URL地址的方法?在我的代码中,我有
RedirectToAction("myaction", "mycontroller", new {arg1= "height", arg2="weight"})
浏览器中显示的地址是:
http/mywebsite/mycontroller/myaction?arg1=height&arg2=weight
我想在浏览器网址中显示的内容是:
http://mywebsite/height/weight
有没有办法实现这个目标?
答案 0 :(得分:0)
您需要添加一个特定的路由来实现这一点,只需在Global.asax.cs中将应用程序的Map Route添加到应用程序中:
protected void Application_Start()
{
RouteTable.Routes.MapRoute("myRouteName",
"/{height}/{weight}",
new { controller = "mycontroller", action = "myaction" },
new[] { "Namespace.Of.My.Controller" });
}