ASP.NET MVC 出现错误 “The view 'XXX' or its master was not found or no view engine support”

时间:2022-03-01 06:46:47

来自:http://www.dengyukeji.com/archiver/tid-151.html

错误如下:The view 'XXX' or its master was not found or no view engine supports the searched locations.

The following locations were searched:
~/Views/XXX/XXX.aspx
~/Views/XXX/XXX.ascx
~/Views/Shared/XXX.aspx
~/Views/Shared/XXX.ascx
~/Views/XXX/XXX.cshtml
~/Views/XXX/XXX.vbhtml
~/Views/Shared/hotgoodslist.cshtml
~/Views/Shared/hotgoodslist.vbhtml网上比较少这些资料;
但是你总找不到原因,其实原因很简单,就是因为你的这个路由地址找不到了。The following locations were searched:
~/Views/XXX/XXX.aspx
~/Views/XXX/XXX.ascx
~/Views/Shared/XXX.aspx
~/Views/Shared/XXX.ascx
~/Views/XXX/XXX.cshtml
~/Views/XXX/XXX.vbhtml
~/Views/Shared/hotgoodslist.cshtml
~/Views/Shared/hotgoodslist.vbhtml这些代码的意思就是说以下的这些项会被搜索,所有的请求都会按下面的地址进行查询搜索,直到找到匹配的为止,报这个错,就是因为你的路由中在你的View文件夹中找不到了。
解决方案:
首要检查的就是你的View跟你写的路由地址的Action名称是否一致。
我要在做项目的时候就是因为这个名称不一致导致的,比如我的路径是/XXXX/XXXXManager/XXXCreate
但是我实际的View中的文件名称是XXXCraete。说实话这个问题是很难查的。
不过教大家一个方法:~/Views/XXX/XXX.aspx
~/Views/XXX/XXX.ascx
~/Views/Shared/XXX.aspx
~/Views/Shared/XXX.ascx
~/Views/XXX/XXX.cshtml
~/Views/XXX/XXX.vbhtml
~/Views/Shared/hotgoodslist.cshtml
~/Views/Shared/hotgoodslist.vbhtml就是按照这个地址去你的View文件夹里面找一遍,看看是不是由于不致导致的,就可以了。
其实要检查的就是你的路由配置没写好。这个我还没碰到过,有碰到过的朋友请告诉我。

今天把项目发布IIS的时候,出现这个问题,解决方法 :/Views/XXX/下缺少XXX.cshtml文件,直接把电脑上的XXX.cshtml文件拷贝到IIS的对应的路径就可以了。