C# 控制器';s动作参数不';不接受/
我有控制员的行动C# 控制器';s动作参数不';不接受/,c#,asp.net-mvc,routes,C#,Asp.net Mvc,Routes,我有控制员的行动 public string Index(string id) { return id; } 我在Global.asax.cs中只有这条路线 routes.MapRoute( "Default", "{id}", new { controller = "Start", action = "Index", id = UrlParameter.Optional }
public string Index(string id)
{
return id;
}
我在Global.asax.cs中只有这条路线
routes.MapRoute(
"Default",
"{id}",
new { controller = "Start", action = "Index", id = UrlParameter.Optional }
);
对于像这样的url“http://localhost/stuff“和”http://localhost/hello“它起作用了。但它对url不起作用,比如“http://localhost/stuff/add". 如何修复它?在id之前添加通配符(星号):
routes.MapRoute(
"Default",
"{*id}",
new {controller = "Start", action = "Index", id = UrlParameter.Optional}
);
您希望它如何工作?/home/staff必须显示字符串“home/staff”。但是现在“/hello”显示“hello”(正常工作)和/hello/test显示错误“id”不能包含“/”。这不是使用路由的正确方法。