Asp.net mvc 在mvc3中添加带有url的额外参数
我是asp.net mvc3的新手。我想在控制器前面添加url的额外参数,如:-Asp.net mvc 在mvc3中添加带有url的额外参数,asp.net-mvc,asp.net-mvc-3,routing,Asp.net Mvc,Asp.net Mvc 3,Routing,我是asp.net mvc3的新手。我想在控制器前面添加url的额外参数,如:- Newparameter/{controller}/{action}/{id}; 这是可能的,我也需要改变它的价值 请帮助……是的,这是可能的,只需在Global.asax中添加一条新路线,如下所示: routes.MapRoute( "Default with new param", // Route name "{newParameter}/{controlle
Newparameter/{controller}/{action}/{id};
这是可能的,我也需要改变它的价值
请帮助……是的,这是可能的,只需在Global.asax中添加一条新路线,如下所示:
routes.MapRoute(
"Default with new param", // Route name
"{newParameter}/{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
将其放在默认路线之前,因为它更具体
然后创建一个将“newParameter”作为方法参数的操作方法您必须在
Global.ascx
中定义一个新路由
routes.MapRoute(
"RouteName",
"{Param}/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
别忘了把你的新路线放在默认路线之上