ASP.NET MVC]路线比赛,但从未控制器叫。 - > 404 [英] ASP.NET MVC] Route match but controller never called. -> 404
问题描述
大家好我有一个MVC3路由和地区问题:
Hi everyone I have a problem with MVC3 routing and areas:
我的路线的比赛,但控制器不会被调用,而不是我得到一个404错误。
My route matches but the controller is never called, instead i get a 404 error.
我设置了MVC3溶液2项目:
I have set an MVC3 solution with 2 project:
- 一个是主要的MVC项目:CityServices
- 对于一个面积:CityServices.Demo
在我的领域我注册下列路线:
In my area I register the following route:
public class TestAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Test";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Test_default",
"Test/{controller}/{action}",
new { controller = "Stuff", action = "ListAll" }
);
}
}
StuffController.cs内容:
Content of StuffController.cs:
public class StuffController : Controller
{
public ActionResult ListAll()
{
List<Stuff> lstStuff = new List<Stuff>
{
new Stuff()
{
Id = 0,
Name = "HEeey",
Value = 10.456f
},
new Stuff()
{
Id = 1,
Name = "Beeee",
Value = 456789.47879999f
},
new Stuff()
{
Id = 2,
Name = "HooAAaoo",
Value = 0f
}
};
return Json(lstStuff);
}
}
我在主项目登记面积:
I register area in the main project:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
//RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
}
我的路线匹配:的http://主机/测试
但我总是得到一个404错误。
My route is matched: http://host/Test But i always get a 404 error.
任何想法?
谢谢,
- 杰里米
Thanks, - Jeremy
编辑:这是一个证明,路由匹配:
Here is a proof that the route matches:
找到解决方案
所以总结起来。
我AreaRegistration继承类是不是在同一个命名空间我的控制器。
因为我没有任何意见(它只是一个宁静websvc)我没有使用MvcContribs似乎当你有意见和放大器是有用的;在控制器比主站点型动物项目
So to sum it up. My AreaRegistration inherited class was not in the same namespace as my controllers. Since i did not have any views (it's just a restful websvc) i did not have to use MvcContribs which seems to be useful when you have views&controllers in a differents project than the main site.
希望这有助于你在这个问题上到达;)
Hope this helps if you arrive on this question ;)
推荐答案
您在另一个项目中的区域,除非您使用的是便携式MvcContribs地区或其他自定义实现,不会每默认工作
You have your area in another project which won't work per default unless you are using MvcContribs portable areas or another custom implementation
这篇关于ASP.NET MVC]路线比赛,但从未控制器叫。 - &GT; 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!