【发布时间】:2023-06-19 08:41:02
【问题描述】:
我有一个包含部分视图的 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");
但无论如何,如果有人有更好的想法,那将是受欢迎的。
【问题讨论】:
-
看来我刚刚通过将返回行替换为:return PartialView("../Grids/_CompGrid");但如果有人有更好的想法,请提出建议。
标签: asp.net-mvc asp.net-mvc-4 asp.net-mvc-partialview