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

后端 未结 5 1974
挽巷
挽巷 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:45

    you can specified in Routes.cs

     routes.MapRoute(
     name: "College",
     url: "Student/{studentId}",
     defaults: new { controller = "Student", action = "Details"}
     );
    

    We can define such a constraint as

      routes.MapRoute(
      name: "College",
      url: "Student/{studentId}", 
      defaults: new { controller = "Student", action = "Details"},
      constraints:new{id=@"\d+"} 
      ); 
    

提交回复
热议问题