asp.net-mvc之如何使用 ASP.NET MVC 路由设置 RESTFul URL
lovecherry
阅读:99
2024-06-20 12:54:19
评论:0
我有这个网址:
/controller/action/value
还有这个 Action :
public ActionResult Get(string configName,string addParams)
{
}
如何设置路由表以使路由引擎将值绑定(bind)到 configName
参数以用于 Config
Controller 中的任何操作?
请您参考如下方法:
嗯,首先,这是不完整的。你没有方法名。
其次,这已经适用于以下格式的 URL:
/controller/action?configName=foo&addparams=bar
以下是使用漂亮路线的方法:
routes.MapRoute(
"YourMapping",
"{controller}/{action}/{configName}/{addParams}");
或
routes.MapRoute(
"YourMapping",
"{controller}/{configName}/{addParams}",
new {
controller = "YourController",
action = "YourAction"
},
new {
controller = "YourController" // Constraint
});
如果您想从 URL 中排除操作。
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。