Mike Upjohn
Mike Upjohn

Reputation: 1297

MVC5 Project - Naming Conventions

I've started a new MVC project, and this is my first where its pure MVC without CMS integrations or otherwise. I'm looking for advice on naming conventions, as I am aware there are going to be a lot of controls and forms that are re-used.

Is it sensible to create say a Controls Controller for these re-usable items and call them from my views as appropriate? Also, would there then be a way to stop someone navigating to that Controls/MyControl URL directly?

Thanks, Mike.

Upvotes: 0

Views: 154

Answers (1)

Alexei Levenkov
Alexei Levenkov

Reputation: 100527

To stop one from navigating to Controls/MyControl you just need to add ChildActionOnly attribute:

[ChildActionOnly]
ActionResult MyControl(...){...}

Naming/grouping is up to you - you can start with one controller and see if controls need to be split into groups later.

Note that you may not even need controller for most of the controls as long as they just show data - @Html.RenderPartial("MyControl", dataForControl) may be enough (assuming Razor and existence of "MyControl.cshtml")

Upvotes: 1

Related Questions