Returning partial view in specific folder
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:Projects2012AMT2014_PrototypeAMT2014_PrototypeViewsSearchContactSearch.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.
please refer to the following link for a more detailed explanation of how to fix your problem - The view must derive from WebViewPage, or WebViewPage<TModel>
But basically, the issue is that since you put the partial view in a custom location there is no web.config there that has a RAZOR include.
Try including a copy of your web.config in your partialviews folder and see if it works
链接地址: http://www.djcxy.com/p/42102.html上一篇: 部分视图无法在ajax上调用mvc5
下一篇: 在特定文件夹中返回部分视图