MVC3: How to specify that a partial view be loaded when it is located in another, unexplored folder?

I am trying to include a partial view in a view that is in a different folder. Therefore, I have the following view:

/_mvc/Views/Home/Index.cshtml 

It has the following line of code:

 @Html.Partial("~/_mvc/Views/Subject/_QuickSearch.cshtml", Model.QuickSearchModel); 

This does not work. I keep getting the following error:

 The partial view '~/_mvc/Views/Subject/_QuickSearch' was not found or no view engine supports the searched locations. The following locations were searched: ~/_mvc/Views/Subject/_QuickSearch 

Am I missing something obvious? I must indicate that I changed the routing for my application to put all the MVC code in the _mvc folder. It's not a mistake. The application is in the process of converting from WebForms to MVC, and I wanted all the MVC materials to be in the same folder.

+4
source share
1 answer

If the root of your application is the _mvc / folder, then all you have to do is:

 @Html.Partial("~/Views/Subject/_QuickSearch.cshtml", Model.QuickSearchModel); 

In your case, ~ already points to mvc _ / .

+6
source

All Articles