mare
mare

Reputation: 13083

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?

Upvotes: 3

Views: 2114

Answers (2)

amurra
amurra

Reputation: 15401

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.

Upvotes: 0

Joe Wilson
Joe Wilson

Reputation: 5671

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.

Upvotes: 3

Related Questions