【问题标题】: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")]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-30
        • 2016-10-03
        • 2021-09-18
        • 2013-07-16
        • 2019-03-13
        • 2019-02-26
        • 2014-05-01
        • 1970-01-01
        相关资源
        最近更新 更多