How to Change ASP.NET MVC Controller Name in URL?

后端 未结 5 1966
挽巷
挽巷 2020-12-17 09:56

If we have \"example_name\" we can change it in url using [ActionName(\"\")] So, i want to do this for controller name.

I can do t

5条回答
  •  清酒与你
    2020-12-17 10:36

    You can do this via the Routes.cs

    routes.MapRoute(
          name: "Controller",
          url: "example-controller/{action}",
          defaults: new { 
          controller = "ControllerName", action ="Index"
          }   
    );
    

    There is also another way, if you look at the answer of this question: How to achieve a dynamic controller and action method in ASP.NET MVC?

提交回复
热议问题