我有一个视图,我尝试使用以下代码包含部分:
<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文件,哪有什么不对?
答案 0 :(得分:4)
如果您希望视图引擎仅搜索Razor文件,请在app_start
中添加ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
答案 1 :(得分:4)
实际上_LatestLog
区域中没有Primary
部分视图。
你可以在这里做三件事:
或者您可以在其他某个区域保留局部视图,并通过提供以下路径来调用该局部视图:
@Html.Partial("~/Areas/Primary/Views/PrimaryPersonnelRoleWithAuthority/_LatestLog.cshtml")