How to make the controller's name hyphen “-” separated?

后端 未结 4 1236
小蘑菇
小蘑菇 2021-01-05 01:08

I am able to use the

[ActionName(\"My-Action-Name\")]
public ActionResult MyActionName()
{
    return View();
}

But I am facing a problem

4条回答
  •  暖寄归人
    2021-01-05 01:52

    I like the answer of @aleha, but wanted to do this for MapRoute, because I need a route name.

    In such cases, you can do this:

        Route route = routes.MapRoute(
            "RouteName",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    
        route.RouteHandler = new HyphenatedRouteHandler();
    

提交回复
热议问题