繁体   English   中英

Html.Partial搜索aspx而不是cshtml

[英]Html.Partial searches for aspx instead of cshtml

我有一个视图,我尝试使用以下代码包含部分:

<div>
    @Html.Partial("_LatestLog")
</div>

它会导致以下消息出错

Message:  The partial view '_LatestLog.cshtml' was not found or no view engine supports the searched locations. The following locations were searched:
~/Areas/Primary/Views/PrimaryPersonnelRoleWithAuthority/_LatestLog.aspx
~/Areas/Primary/Views/PrimaryPersonnelRoleWithAuthority/_LatestLog.ascx
~/Areas/Primary/Views/Shared/_LatestLog.aspx
~/Areas/Primary/Views/Shared/_LatestLog.ascx
~/Views/PrimaryPersonnelRoleWithAuthority/_LatestLog.aspx

我期望它在同一个文件夹中找到_LatestLog.cshtml文件,哪有什么不对?

如果您希望视图引擎仅搜索Razor文件,请在app_start中添加

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());

实际上, _LatestLog局部视图在Primary区域中不可用。

你可以在这里做3件事:

  • 在该主要区域创建局部视图;
  • 在共享中创建局部视图;
  • 或者您可以在其他区域保留局部视图,并通过提供以下路径来调用该局部视图:

     @Html.Partial("~/Areas/Primary/Views/PrimaryPersonnelRoleWithAuthority/_LatestLog.cshtml") 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM