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?
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.
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.
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.
Can you pass in the full path?
@Html.Partial("~/Views/Projects/_NotesPartial.cshtml")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With