简体   繁体   中英

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.

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")

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