Asp.net mvc MVC3 maproute,其中URL的第一个值是默认控制器和操作的querstring
我想做一条这样的路线:Asp.net mvc MVC3 maproute,其中URL的第一个值是默认控制器和操作的querstring,asp.net-mvc,asp.net-mvc-3,routing,asp.net-mvc-routing,Asp.net Mvc,Asp.net Mvc 3,Routing,Asp.net Mvc Routing,我想做一条这样的路线: routes.MapRoute( "Default", // Route name "{s}", // URL with parameters new { controller = "Home", action = "Index", s = UrlParameter.Optional } ); 其中s是默认控制器和操作的参数。。这可能吗?我也会满足于这样的事情: routes.Ma
routes.MapRoute(
"Default", // Route name
"{s}", // URL with parameters
new { controller = "Home", action = "Index", s = UrlParameter.Optional }
);
其中s是默认控制器和操作的参数。。这可能吗?我也会满足于这样的事情:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{s}", // URL with parameters
new { controller = "Home", action = "Index", s = UrlParameter.Optional }
);
routes.MapRoute(
"qMap", // Route name
"sc/{s}", // URL with parameters
new { controller = "Home", action = "Index", s = UrlParameter.Optional }
);
但两者都不起作用。。我怀疑是因为第一个元素/参数总是期望是控制器?如果您只有以下路由定义(请确保已从RegisterRoutes方法中删除所有其他路由定义): 以及以下控制器:
public class HomeController: Controller
{
public ActionResult Index(string s)
{
...
}
}
表格
http://foo.com/abc
将被路由到主
控制器,并且索引
操作将被调用并传递s=abc
您能否更具体地说明它是如何工作的?
public class HomeController: Controller
{
public ActionResult Index(string s)
{
...
}
}