I am trying to organize my MVC project and more specifically the views and partial views in the project. But because of where the folders are located, I have to give return view a string path.
I have this simple view called ContactSearch.cshtml
@{
ViewBag.Title = "Contact Search";
}
<!-- Partial view - Search criteria -->
@{
//Html.RenderPartial("_EnquiryBreadCrumb", "Enquiry");
@Html.Action("_EnquiryBreadCrumb", "Enquiry")
}
<!-- Partial view - Search results grid -->
@{
}
The enquiry controller then handles the partialview:
public class EnquiryController : Controller
{
#region Partials
public ActionResult _EnquiryBreadCrumb()
{
return View("~/PartialViews/Enquiry/_EnquiryBreadCrumb.cshtml");
}
#endregion
}
When I return view I get this runtime error:
The view at '~/PartialViews/Enquiry/_EnquiryBreadCrumb.cshtml' must derive from WebViewPage, or WebViewPage<TModel>.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The view at '~/PartialViews/Enquiry/_EnquiryBreadCrumb.cshtml' must derive from WebViewPage, or WebViewPage<TModel>.
Source Error:
Line 7: @{
Line 8: //Html.RenderPartial("_EnquiryBreadCrumb", "Enquiry");
Line 9: @Html.Action("_EnquiryBreadCrumb", "Enquiry")
Line 10: }
Line 11:
Source File: c:\Projects\2012\AMT2014_Prototype\AMT2014_Prototype\Views\Search\ContactSearch.cshtml Line: 9
See screenshot for my file structure:
I want to fix this runtime error and display the partial view on the page. I am using MVC 5.