asp.net-mvc – 未找到部分视图或视图引擎不支持搜索的位置

我有以下控制器代码:

public MyController:Controller
{
 public ActionResult Index()
  {
     return View();
  }
 [ChildActionOnly]
 public ActionResult MyPartialViewAction()
 {
    return PartialView("~/Views/Shared/MyCustomFolder/_MyPartialView",PartialViewModel);
 } 
}

我的索引视图具有以下代码:

@HTML.Action("MyPartialViewAction")

当我运行Web应用程序,我得到HttpException与InnerExceptionMessage为:

InnerException {“The partial view ‘~/Views/Shared/MyCustomFolder/_MyPartialView’ was not found or no view engine supports the searched locations. The following locations were searched:\r\n~~/Views/Shared/MyCustomFolder/_MyPartialView”} System.Exception {System.InvalidOperationException}

我到现在为止已经尝试过

尝试将_MyPartialView从〜/ Views / Shared / MyCustomFolder移动到〜/ Views / Shared /和〜/ Views / MyControllerFolder,但仍然存在错误
试着将我的索引查看代码改成@ HTML.RenderAction(),但没有运气。

任何输入,我错了哪里?

谢谢

您需要将.cshtml扩展名添加到视图名称中:

return PartialView("~/Views/Shared/MyCustomFolder/_MyPartialView.cshtml",PartialViewModel);
http://stackoverflow.com/questions/22054264/partial-view-was-not-found-or-no-view-engine-supports-the-searched-locations

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:asp.net-mvc – 未找到部分视图或视图引擎不支持搜索的位置