c# - Html.Partial 搜索 aspx 而不是 cshtml

标签 c# asp.net asp.net-mvc asp.net-mvc-4 razor

我有一个 View ,我尝试使用以下代码包含部分内容:

<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,有什么问题吗?

最佳答案

实际上 _LatestLog 部分 View 在 Primary 区域不可用。

你可以在这里做三件事:

  • 在该主要区域创建局部 View ;
  • 在共享中创建局部 View ;
  • 或者您可以在其他区域保留一个局部 View ,并通过如下路径调用该局部 View :

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

关于c# - Html.Partial 搜索 aspx 而不是 cshtml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29746346/

相关文章:

c# - ASP.Net MVC 在模型错误中定义 PageLink

c# - 在没有标题的情况下将 CSV 文件读入数据集

javascript - 如何使用javascript获取下拉列表的选定值

c# - 获取对象的属性名称和它期望的类型

c# - Dns.BeginGetHost ...方法阻止

c# - 在具有动态参数的 MvcSiteMapProvider 中为 DynamicNode 创建子节点

asp.net-mvc - Azure VM 上的安全 Solr 搜索引擎

c# - 没有科学记数法的 double 字符串转换

c# - Windows 库中是否有树数据类型?

asp.net-mvc - 如何创建可视化数据库模型?