Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net MVC - Can I tell Html.Partial where to find the view?

I have a view that lives in /Views/Projects and I am making a call to render a partial view:

@Html.Partial("_NotesPartial")

The view that I want to render actually exists in the /Views/Notes folder but I can't figure out how to tell MVC to search that folder for this specific call. Is there an overload I can call to have MVC look for this view in this folder instead of Projects and Shared?

like image 216
Dismissile Avatar asked Oct 05 '11 17:10

Dismissile


People also ask

How do you call a partial view inside another partial view?

To call a partial view from another partial view, we follow the same approach as we follow when we call partial view from the content page. Let's take an example. This is the code of 1st partial view. Notice that in above partial view, we are calling another partial view named "_View2" that is created below.

How do you call a partial view in another 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 difference between view and partial view in MVC?

View can basically contains a complete markup which may contain a master view(or master page) with all the design(s) etc. whereas Partial view is only a portion of page or a small markup which don't have master page. It is basically used as user control in mvc and it can be used at more than one views.


1 Answers

Can you pass in the full path?

@Html.Partial("~/Views/Projects/_NotesPartial.cshtml")
like image 172
Michael Haren Avatar answered Oct 19 '22 20:10

Michael Haren