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

前端之家收集整理的这篇文章主要介绍了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);
原文链接:https://www.f2er.com/aspnet/253554.html

猜你在找的asp.Net相关文章