How do I change the url in MVC 5?

2019-05-25 01:10发布

I am trying to change a URL in MVC 5 from "Master" to "Master-Franchise" & I thought the following would work but the URL is still just "Master".

    // GET: Master-Fanchise
    [Route("Master-Fanchise")]
    public ActionResult Master()
    {
        return View();
    }

2条回答
The star\"
2楼-- · 2019-05-25 01:58

Use ActionName attributes which allows you to give action name for controller method regardless of method name.

   [ActionName("Master-Fanchise")]
    public ActionResult Master()
    {
        return View();
    }
查看更多
相关推荐>>
3楼-- · 2019-05-25 02:03

Have you enabled attribute routing as it is not turned on by default

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        //Add this line of code
        routes.MapMvcAttributeRoutes(); 

    }
}

you may also need to change the controller

[Route("~/ControllerName/Master-Fanchise")]
查看更多
登录 后发表回答