Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 部分搜索aspx而不是cshtml_C#_Asp.net_Asp.net Mvc_Asp.net Mvc 4_Razor - Fatal编程技术网

C# 部分搜索aspx而不是cshtml

C# 部分搜索aspx而不是cshtml,c#,asp.net,asp.net-mvc,asp.net-mvc-4,razor,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Razor,我有一个视图,其中我尝试使用以下代码包含一个分部: <div> @Html.Partial("_LatestLog") </div> 我希望它能在同一个文件夹中找到文件_LatestLog.cshtml,有什么问题吗?如果您想让视图引擎只搜索Razor文件,请在应用程序启动时添加此选项 ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine()); 实际上,\u最新日志部

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

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

我希望它能在同一个文件夹中找到文件_LatestLog.cshtml,有什么问题吗?

如果您想让视图引擎只搜索Razor文件,请在应用程序启动时添加此选项

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

实际上,
\u最新日志
部分视图在
区域中不可用

你可以在这里做三件事:

  • 在主区域中创建局部视图
  • 在共享视图中创建局部视图
  • 或者,您可以在其他区域保留局部视图,并通过如下方式调用该局部视图:

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

该错误意味着搜索了以下位置,但未找到您的页面
。请检查您是否在正确的目录中有正确的文件。奇怪的是,它正在查找扩展名为“aspx”或“ascx”的文件,而不是运行MVC4-project时所期望的“cshtml”。真的吗?再次检查:顺便说一句,它也搜索cshtml文件,你可以在你的消息中看到它试图找到所有可用的视图引擎的文件。就像Razor一样,它也使用ASPX查找文件。。检查柱。您可以删除aspx视图引擎。请检查以下语句的运行时值:
ViewEngines.Engines.OfType().Single().FileExtensions
@Html.Partial("~/Areas/Primary/Views/PrimaryPersonnelRoleWithAuthority/_LatestLog.cshtml")