Asp.Net MVC: How do I enable dashes in my urls?

前端 未结 9 1043
礼貌的吻别
礼貌的吻别 2020-11-28 21:52

I\'d like to have dashes separate words in my URLs. So instead of:

/MyController/MyAction

I\'d like:

/My-Controller/My-Act         


        
9条回答
  •  抹茶落季
    2020-11-28 22:48

    You can define a specific route such as:

    routes.MapRoute(
        "TandC", // Route controllerName
        "CommonPath/{controller}/Terms-and-Conditions", // URL with parameters
        new {
            controller = "Home",
            action = "Terms_and_Conditions"
        } // Parameter defaults
    );
    

    But this route has to be registered BEFORE your default route.

提交回复
热议问题