ASP.NET MVC Controller与Areas下面的Controller同名的解决办法
2010-05-17 12:32
411 查看
问题重现:
当项目下:Controller/HomeController.cs时,
人在创建一个域Test,之后在建一个同名的HomeController: Areas/Test/Controller/HomeController.cs
运行报错:
Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}/') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.
The request for 'Home' has found the following matching controllers:
Web.Areas.Test.Controllers.HomeController
Web.Controllers.HomeController
解决办法:
/Areas/Test/TestAreaRegistration.cs
代码
context.MapRoute(
"Test_default",
"Test/{controller}/{action}/{id}/",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "Web.Areas.Test.Controllers"}
);
/Global.asax
routes.MapRoute(
"Home", // Route name
"{controller}/{action}/{id}/", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "Web.Controllers"}
);
当项目下:Controller/HomeController.cs时,
人在创建一个域Test,之后在建一个同名的HomeController: Areas/Test/Controller/HomeController.cs
运行报错:
Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}/') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.
The request for 'Home' has found the following matching controllers:
Web.Areas.Test.Controllers.HomeController
Web.Controllers.HomeController
解决办法:
/Areas/Test/TestAreaRegistration.cs
代码
context.MapRoute(
"Test_default",
"Test/{controller}/{action}/{id}/",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "Web.Areas.Test.Controllers"}
);
/Global.asax
routes.MapRoute(
"Home", // Route name
"{controller}/{action}/{id}/", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "Web.Controllers"}
);
相关文章推荐
- ASP.NET MVC Controller与Areas下面的Controller同名的解决办法
- ASP.NET MVC下面的Controller与Fckeditor.Controllers.HomeController同名的解决办法
- ASP.NET MVC 相同Controller的解决办法
- ASP.NET MVC 3 RC2 版本的一些新特性及AllowHtml属性Bug解决办法
- Asp.Net MVC Html.TextBoxFor日期格式化出错“模板只能用于字段访问、属性访问、一维数组索引或单参数自定义索引器表达式” 解决办法
- asp.net MVC Controller之间解决丢失Cookie
- ASP.NET MVC 4 WebAPI. Support Areas in HttpControllerSelector
- EF Database First with ASP.NET MVC: Creating the Web Application and Data Models开发遇到问题的解决办法
- asp.net mvc放在iis7.5中提示404错误 js异步请求失效解决办法
- asp.net mvc Ajax.BeginForm不能异步刷新,或转到新页面,或页面还是刷新了,的原因(或解决办法)(转)
- ASP.NET MVC几种找不到资源的问题解决办法
- asp.net MVC FileResult在IE下异常的解决办法
- ASP.NET MVC 解决区域和全局控制器同名的问题
- ASP.NET MVC引用最新Newtonsoft.Json的异常问题解决办法
- 使用Asp.net MVC 2.0 +.NET 4.0 出现 “从客户端 ... 中检测到有潜在危险的 Request.Form 值”错误的解决办法
- ASP.NET MVC 程序 报错“CS0012: 类型“System.Data.Objects.DataClasses.EntityObject”在未被引用的程序集中定义”的解决办法
- ASP.NET MVC 使用jquery.form.js 异步上传 在IE下返回值被变为下载的解决办法
- asp.net mvc在添加视图时候看不到模型类的解决办法
- ASP.NET MVC在IIS7下发布无法显示的解决办法
- Asp.net MVC中不使用IFrame 引起的客户端 验证失败的解决办法