MVC区 - 查看没有发现 [英] MVC Areas - View not found
问题描述
我有一个使用MVC领域的项目。该地区拥有它整个项目而主要的视图/控制器/模型文件夹中的区外空除非有调度控制器我已经设置了默认路由传入请求到主控制器在我的领域。
I have a project that is using MVC areas. The area has the entire project in it while the main "Views/Controllers/Models" folders outside the Areas are empty barring a dispatch controller I have setup that routes default incoming requests to the Home Controller in my area.
该控制器具有一个方法如下: -
This controller has one method as follows:-
public ActionResult Index(string id)
{
return RedirectToAction("Index", "Home", new {area = "xyz"});
}
我也有一个默认路由设置为使用此控制器如下: -
I also have a default route setup to use this controller as follows:-
routes.MapRoute(
"Default", // Default route
"{controller}/{action}/{id}",
new { controller = "Dispatch", action = "Index", id = UrlParameter.Optional }
);
任何默认请求到我的网站被适当地路由到相关区域。该地区的RegisterArea方法有一个路线: -
Any default requests to my site are appropriately routed to the relevant area. The Area's "RegisterArea" method has a single route:-
context.MapRoute(
"xyz_default",
"xyz/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
我区有很多意见多个控制器。在这些控制器方法,比如特定视图的任何调用返回视图(嗒嗒);
使正确的观点。但是每当我试着和一个模型对象一起返回一个视图传递作为参数我得到的
以下错误: -
My area has multiple controllers with a lot of views. Any call to a specific view in these controller methods like "return View("blah"); renders the correct view. However whenever I try and return a view along with a model object passed in as a parameter I get the following error:-
Server Error in '/DeveloperPortal' Application.
The view 'blah' or its master was not found. The following locations were searched:
~/Views/Profile/blah.aspx
~/Views/Profile/blah.ascx
~/Views/Shared/blah.aspx
~/Views/Shared/blah.ascx
看起来每当一个模型对象传递作为一个参数等。到查看()方法[如返回视图(嗒嗒,OBJ)它会搜索视图
在项目,而不是在该地区的特定视图文件夹的根目录。
It looks like whenever a model object is passed in as a param. to the "View()" method [e.g. return View("blah",obj) ] it searches for the view in the root of the project instead of in the area specific view folder.
我是什么在这里失踪?
先谢谢了。
推荐答案
如果您使用,而不是
context.MapRoute(
"xyz_default",
"xyz/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
使用
context.MapRoute(
"xyz_default",
"{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
在
xyzAreaRegistration.cs
xyzAreaRegistration.cs
那么你就不需要在任何一个环节明确指定区域...
then you don't need to explicitly specify your area in any link...
这篇关于MVC区 - 查看没有发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!