Asp.net mvc 5 返回特定文件夹中的部分视图

Asp.net mvc 5 返回特定文件夹中的部分视图,asp.net-mvc-5,partial-views,Asp.net Mvc 5,Partial Views,我试图组织我的MVC项目,更具体地说是项目中的视图和局部视图。但是由于文件夹位于何处,我必须给返回视图一个字符串路径 我有一个简单的视图叫做ContactSearch.cshtml @{ ViewBag.Title = "Contact Search"; } <!-- Partial view - Search criteria --> @{ //Html.RenderPartial("_EnquiryBreadCrumb", "Enquiry"); @Ht

我试图组织我的MVC项目,更具体地说是项目中的视图和局部视图。但是由于文件夹位于何处,我必须给返回视图一个字符串路径

我有一个简单的视图叫做ContactSearch.cshtml

@{
    ViewBag.Title = "Contact Search";
}

<!-- Partial view - Search criteria -->
@{
    //Html.RenderPartial("_EnquiryBreadCrumb", "Enquiry");
    @Html.Action("_EnquiryBreadCrumb", "Enquiry")
}


<!-- Partial view - Search results grid -->
@{

}
返回视图时,出现以下运行时错误:

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 
“~/PartialViews/Enquiry/\u inquiryByReadCrumb.cshtml”上的视图必须派生自WebViewPage或WebViewPage。 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源。 异常详细信息:System.InvalidOperationException:“~/PartialViews/inquiry/\u inquiryByReadCrumb.cshtml”处的视图必须派生自WebViewPage或WebViewPage。 源错误: 第7行:@{ 第8行:://Html.RenderPartial(“\u inquirybreadcrumb”,“inquiry”); 第9行:@Html.Action(“\u inquirybreadcrump”,“inquiry”) 第10行:} 第11行: 源文件:c:\Projects\2012\AMT2014\u Prototype\AMT2014\u Prototype\Views\Search\ContactSearch.cshtml行:9 有关我的文件结构,请参见屏幕截图:


我想修复此运行时错误并在页面上显示部分视图。我使用的是MVC 5。

请参考以下链接,了解如何解决问题的更详细说明-

但基本上,问题在于,由于您将部分视图放在自定义位置,因此那里没有包含RAZOR include的web.config


尝试在partialviews文件夹中包含web.config的副本,看看它是否有效

我最终这样做了,因此如果有人想要自定义视图文件夹,这个答案是正确的。
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