【发布时间】:2014-06-05 13:08:14
【问题描述】:
使用 ajax 我在 asp.net mvc 控制器操作上收到某些字符串。基于该字符串值,我想呈现部分视图。
public ActionResult GetTabData(string activeTab)
{
string viewName = String.Empty;
switch (activeTab)
{
case "all":
viewName = "_AllPartial";
break;
case "one":
viewName = "_OnePartial";
break;
case "two":
viewName = "_TwoPartial";
default:
viewName = "_AllPartial";
break;
}
return PartialView("/Home/"+viewName);
}
所有部分视图都存储在 Views/Home 目录中,但我经常收到无法找到部分视图的错误
The partial view '/Home/_AllPartial' was not found or no view engine supports the searched locations. The following locations were searched:
/Home/_AllPartial
【问题讨论】:
-
也许以波浪号开头:“~/Home/”?
-
您需要一个自定义的 ViewEngine 来执行此操作,请参阅下面的答案。
标签: c# .net asp.net-mvc