.NET MVC 4.5 重写索引路由
.NET MVC 4.5 rewrite index route
目前我有这样的控制器:
class AccountController : Controller {
public ActionResult Index() {
return View();
}
}
没关系,除了用户进入此页面时会有一部分 url:
http://myhost/account/index
,这是不需要的。我怎么能只有http://myhost/account
?
像这样的东西可以解决问题
routes.MapRoute(
name: "Account",
url: "account/{action}/{id}",
defaults: new { controller = "Account", action = "Index", id = UrlParameter.Optional }
);
也可以使用属性路由装饰 [Route]
您希望成为默认方法的方法来完成。
目前我有这样的控制器:
class AccountController : Controller {
public ActionResult Index() {
return View();
}
}
没关系,除了用户进入此页面时会有一部分 url:
http://myhost/account/index
,这是不需要的。我怎么能只有http://myhost/account
?
像这样的东西可以解决问题
routes.MapRoute(
name: "Account",
url: "account/{action}/{id}",
defaults: new { controller = "Account", action = "Index", id = UrlParameter.Optional }
);
也可以使用属性路由装饰 [Route]
您希望成为默认方法的方法来完成。