【发布时间】:2017-07-10 17:09:23
【问题描述】:
在我的控制器中我定义了:
const string KList = "list.cshtml";
我调用 Action 方法:
public ActionResult All()
{
var view = Empty();
var model = new Model(); // some other code to get the model
view = PartialView(KList, model);
return view;
}
这里是视图:
我得到这个错误:
System.Web.HttpException: '执行处理程序的子请求时出错 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'。'
InnerException: InvalidOperationException:未找到局部视图“list.cshtml”或没有视图引擎支持搜索 地点。搜索了以下位置:
~/Views/Communication/list.cshtml.aspx
~/Views/Communication/list.cshtml.ascx
~/Views/Shared/list.cshtml.aspx
~/Views/Shared/list.cshtml.ascx
为什么要在视图文件中附加 aspx 和 ascx?
【问题讨论】:
-
这里缺少一些东西,如果你调用
return View(),它不会搜索“list”,除非你执行return View(KList)之类的操作。然后,您需要将KList更改为“list”而不是“list.cshtml”。 -
@Alisson ,刚刚更正了。感谢您的指出。
-
不客气,如果有帮助,我会回答更多细节。
标签: c# asp.net-mvc-4 razor