开发者

Add a - into a MVC3 controller name

开发者 https://www.devze.com 2023-03-26 07:12 出处:网络
This might be a stupid question but I want to add a - into a controlle开发者_StackOverflowr name e.g. feature-request

This might be a stupid question but I want to add a - into a controlle开发者_StackOverflowr name e.g. feature-request

How do I do this? I have tried creating one with a view however it can't be found.

Can anyone point me in the right direction?


Using the standard conventions in the MVC framework, you can't. Why? Because C# (actually .NET itself) doesn't support - in type names.

I suspect you want this to allow your users to go to http://yoursite.com/feature-request/add or something - in that case, just add a route that sends them to the correct place.

routes.Map("FeatureRequestsRoute", "~/feature-requests/{action}/{id}",
    new { controller = "FeatureRequest", action = "Index", id = UrlParameter.Optional });

Be sure to add the routes in the correct order - the default route matches anything, so this route has to be added before the default route.

0

精彩评论

暂无评论...
验证码 换一张
取 消