我正在使用带有区域的路线属性。
我的路线配置是:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "Peacock.Controllers" }
);
routes.MapRoute(
"CMS",
"CMS/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "CMS.Controllers" }
);
}
在我当地的每件事情都是正确的!今天,当我发布我的项目并将其上传到我的主机上时,我遇到了两类错误。
如果我请求默认MapRoute的网址,例如mysite.com/Contents/1060
,一切都是正确的!但是,当我要求我所在区域的网址时,我遇到了两类错误!
1)mysite.com/cms/comment
或mysite.com/cms/category
等一些请求出现此错误:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Areas/CMS/Views/ContentCategory/Index.aspx
~/Areas/CMS/Views/ContentCategory/Index.ascx
~/Areas/CMS/Views/Shared/Index.aspx
~/Areas/CMS/Views/Shared/Index.ascx
~/Views/ContentCategory/Index.aspx
~/Views/ContentCategory/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Areas/CMS/Views/ContentCategory/Index.cshtml
~/Areas/CMS/Views/ContentCategory/Index.vbhtml
~/Areas/CMS/Views/Shared/Index.cshtml
~/Areas/CMS/Views/Shared/Index.vbhtml
~/Views/ContentCategory/Index.cshtml
~/Views/ContentCategory/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
但我的主人上存在~/Areas/CMS/Views/ContentCategory/Index.cshtml
!
2)mysite.com/cms/content
或mysite.com/cms/gallery
等其他一些请求出现此错误:
The partial view '~/Content/templates///views/Gallery/index.cshtml' was not found or no view engine supports the searched locations. The following locations were searched:
~/Content/templates///views/Gallery/index.cshtml
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The partial view '~/Content/templates///views/Gallery/index.cshtml' was not found or no view engine supports the searched locations. The following locations were searched:
~/Content/templates///views/Gallery/index.cshtml
Source Error:
Line 3: string view = "~/Content/templates/" + ViewBag.website + "/" + ViewBag.lang + "/views/Gallery/index.cshtml";
Line 4: Html.RenderPartial(view);
Line 5: }
Line 6:
源错误'这个错误的一些代码显示了我的默认项目(不是cms)的galleryController视图! 我很困惑。
我再次强调这只发生在主机和我的本地系统上,每件事都是正确的!
还应该注意的是,这个错误发生在今天又出现了另一个错误,昨天在我的主机上一切都被纠正了,这个错误直到昨天才发生!
答案 0 :(得分:1)
我有同样的问题!我错误地将'Areas'文件夹重命名为'Area'并遇到了这个错误!
错误2:在默认项目中有一个与所请求控制器名称相同的控制器时发生!
错误1:当你在Default项目中没有一个与所请求控制器名称相同的控制器时发生!
祝你好运。答案 1 :(得分:0)
我不知道这是否是您唯一的问题,但您的路线列出的顺序错误。
您配置路由的方式,以CMS
开头的任何2或3段网址将与Default
路由匹配,而不是CMS
路由。由于此问题,您可能无法找到您的视图,因为正在使用错误的命名空间(因此调用了错误的控制器)。要解决此问题,您应该在CMS
之前注册Default
路由。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
"CMS",
"CMS/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "CMS.Controllers" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new[] { "Peacock.Controllers" }
);
}
当然,该错误也可能表示您尚未将所有视图完全部署到服务器。