【问题标题】:How do I change the url in MVC 5?如何更改 MVC 5 中的 url?
【发布时间】:2015-09-11 15:10:37
【问题描述】:
我正在尝试将 MVC 5 中的 URL 从“Master”更改为“Master-Franchise”,我认为以下方法可行,但该 URL 仍然只是“Master”。
// GET: Master-Fanchise
[Route("Master-Fanchise")]
public ActionResult Master()
{
return View();
}
【问题讨论】:
标签:
asp.net-mvc
asp.net-mvc-5
【解决方案1】:
使用ActionName 属性,它允许您为控制器方法指定操作名称,而不管方法名称如何。
[ActionName("Master-Fanchise")]
public ActionResult Master()
{
return View();
}
【解决方案2】:
您是否启用了属性路由,因为它默认没有打开
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//Add this line of code
routes.MapMvcAttributeRoutes();
}
}
您可能还需要更换控制器
[Route("~/ControllerName/Master-Fanchise")]