我有一个 asp.net mvc4 视图,其中包括一些部分视图。这个视图还包含一个提交按钮来过滤网格中的一些元素,见下文:
配置.cshtml
<div id="MyDiv">
@Html.Partial("../Grids/_CompGrid")
</div>
@using (Ajax.BeginForm("Search", "Component", ...)
{
<input type="submit" name="_search" value="@Resource.CaptionComponentApplyFilter" />
}
组件控制器.cs
public PartialViewResult Search()
{
// Do some stuff
return PartialView("_CompGrid");
}
当返回上面的部分视图时,它会崩溃。似乎它没有处理部分视图的正确路径。请参阅以下消息错误:
The partial view '_CompGrid' was not found or no view engine supports the searched locations.
The following locations were searched:
~/Views/Component/_CompGrid.aspx
~/Views/Component/_CompGrid.ascx
~/Views/Shared/_CompGrid.aspx
~/Views/Shared/_CompGrid.ascx
~/Views/Component/_CompGrid.cshtml
~/Views/Component/_CompGrid.vbhtml
~/Views/Shared/_CompGrid.cshtml
~/Views/Shared/_CompGrid.vbhtml
下面是上述文件的目录结构概述。
/root
|
|__ Controllers
| |
| |__ ComponentController.cs
|
|__ Views
| |
| |__ Home
| | |
| | |__ Configure.cshtml
| |
| |__ Grids
| | |
| | |__ _CompGrid.cshtml
| |
| |
关于如何解决这个问题的任何想法?
解决方案:
在函数中替换下面的返回行:
public PartialViewResult Search()
{
// Do some stuff
return PartialView("_CompGrid");
}
经过:
return PartialView("../Grids/_CompGrid");
但无论如何,如果有人有更好的主意,那将是受欢迎的。