42

Would someone confirm the best place for a partial view in ASP.NET MVC?

My thinkings are if it's a global view that's going to be used in many places then SHARED.

If it's part of a view that's been wrapped up into a partial view to make code reading easier, then it should go into the Views/Controller directory

Am I correct or am I missing something?

halfer
  • 19,824
  • 17
  • 99
  • 186
Martin
  • 23,844
  • 55
  • 201
  • 327

2 Answers2

33

I believe you are correct. Here is an example of something I do, general navigation partial views in my Shared directory. and then a partial views for a specific Controller in the Views/[ControllerName] Directory.

John Hartsock
  • 85,422
  • 23
  • 131
  • 146
  • I guess there's really not much different than regular views in the case of placing partial views at controller directory...except partial views don't specify a layout file and the '_' prefix? In other words, we can use regular views as partial views? – Chih-Ho Andy Chou Apr 11 '17 at 15:33
8

I think, you're absolutely right!

Views in the "Views/Shared" folder you can access from all controllers and actions. Views in the "Views/[ControllerName]" folder are for controller specific views only (even if there are possibilities to access them from other controllers).

davehauser
  • 5,844
  • 4
  • 30
  • 45