局部视图没有被发现或没有视图引擎支持搜索到的位置 [英] partial view was not found or no view engine supports the searched locations
问题描述
我有以下控制器code:
I have following controller code:
public MyController:Controller
{
public ActionResult Index()
{
return View();
}
[ChildActionOnly]
public ActionResult MyPartialViewAction()
{
return PartialView("~/Views/Shared/MyCustomFolder/_MyPartialView",PartialViewModel);
}
}
和我的索引视图有以下code:
and my Index view has the following code :
@HTML.Action("MyPartialViewAction")
当我运行Web应用程序,我得到HttpException与InnerExceptionMessage为:
When I run the Web app I get HttpException with InnerExceptionMessage as :
{的InnerException局部视图〜/查看/共享/ MyCustomFolder / _MyPartialView未找到或没有视图引擎支持的搜索位置以下地点进行了全面搜查:\\ r \\ n〜/查看/共享/ MyCustomFolder / _MyPartialView} {System.Exception的} System.InvalidOperationException
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
从〜/查看/共享/ MyCustomFolder
到〜/查看/共享/
和〜/查看/ MyControllerFolder
,但仍然存在错误
Tried moving
_MyPartialView
from~/Views/Shared/MyCustomFolder
to~/Views/Shared/
and~/Views/MyControllerFolder
but still error exists
试图改变我的索引视图code到 @ HTML.RenderAction()
,但没有运气。
Tried changing my Index View code to @HTML.RenderAction()
but no luck.
这是我要去哪里不对任何投入?
Any inputs on where I'm going wrong ?
感谢
推荐答案
您需要将.cshtml扩展添加到视图名称:
You need to add the .cshtml extension to the view name:
return PartialView("~/Views/Shared/MyCustomFolder/_MyPartialView.cshtml",PartialViewModel);
这篇关于局部视图没有被发现或没有视图引擎支持搜索到的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!