在其他文件夹而不是 Views 文件夹中调用 PartialView 时,出现“必须从 WebViewPage 派生”错误。
错误
System.InvalidOperationException: The view at '~/Modules/HtmlContent/_HtmlContent.cshtml' must derive from WebViewPage, or WebViewPage<TModel>.
PartialView adding
页面.cshtml
<div class="side">
@Html.Action("Side")
</div>
家庭控制器.cs
public ActionResult Side()
{
return PartialView("~/Modules/HtmlContent/_HtmlContent.cshtml");
}
文件层次结构
Modules
|
+-- HtmlContent
| |
| +-- _HtmlContent.cshtml
|
Views
|
+-- Home
| |
| +-- Index.cshtml
| |
| +-- Page.cshtml
|
+-- Shared
|
+-- Layout.cshtml
|
+-- _Partial.cshtml