简体   繁体   中英

Naming conventions for ASP.NET MVC routes

From Rails and some people's ASP.NET MVC examples I got the feeling that routes are mostly written in lowercase. C# conventions do require uppercase classes and method names so controllers and controller action's will remain uppercase but I'm wondering if I should start writing routes in global.asax.cs in all lowercase (as opposed to what I do now, which is uppercase).

This

routes.MapRoute("GetPosts", "PostCode/GetPosts", new { controller = "PostCode", action = "GetPosts" });

or this

routes.MapRoute("getposts", "postCode/getposts", new { controller = "PostCode", action = "GetPosts" });

or this

routes.MapRoute("posts", "postcode/posts", new { controller = "PostCode", action = "GetPosts" });

or something else?

I prefer camel case for the route name and url pattern the way it is in your first example.

You can also create a static file of public constants to store route names if you need to use them in other places. Then you can reference MyRouteNames.Posts and MyRouteNames.GetPosts to encapsulate the strings.

It's really up to you and which way you prefer. I prefer to use upper case since that is what I am used to doing, but I don't think there is any right/wrong way in this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM