MVC3: How to specify that a partial view be loaded when it is located in a different, non-searched, folder?
I am trying to include a partial view in a view that is located in a different folder. So 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 is not working. 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/_Quic开发者_如何学CkSearch
Am I missing something obvious? I should point out that I have modified the routing for my application to place all MVC code in the _mvc folder. This is not a mistake. The application is in the process of being converted from WebForms to MVC and I wanted all the MVC stuff under one folder.
If the root of your application is the _mvc/ folder, then all you should need to do is:
@Html.Partial("~/Views/Subject/_QuickSearch.cshtml", Model.QuickSearchModel);
In your case, ~ already points to mvc_/.
精彩评论