Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct place for Partial Views in ASP.NET MVC?

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?

like image 742
Martin Avatar asked Nov 04 '10 00:11

Martin


People also ask

Where do you put partial views?

You can place the partial view in the Shared folder or you can store it under the controller-specific subfolder. It would to shared if used by multiple controllers and it would better go to the controller view folder if only used by a single controller.

What is partial views in ASP NET MVC?

A partial view is a Razor markup file ( . cshtml ) without an @page directive that renders HTML output within another markup file's rendered output. The term partial view is used when developing either an MVC app, where markup files are called views, or a Razor Pages app, where markup files are called pages.

How we can use partial view in MVC?

To create a partial view, right-click on view -> shared folder and select Add -> View option. In this way we can add a partial view. It is not mandatory to create a partial view in a shared folder but a partial view is mostly used as a reusable component, it is a good practice to put it in the "shared" folder.

What is the right way to render partial view?

Rendering a Partial View You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html. RenderAction() .


1 Answers

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.

like image 166
John Hartsock Avatar answered Oct 04 '22 20:10

John Hartsock