2012-11-07 74 views
1

我在ASP MVC是新手,目前,我的演示项目结构是这样的:ASP MVC路由配置 - 资源无法找到错误

Areas -- Comment -- Controller -- HomeController 
           -- ManageController 
Controller -- HomeController 
      |-- CommentController 
       |____ PostMsg 
       |____ DeleteMsg 
Views -- Home 
    |  |--- Index.cshtml 
    |-- Comment 
      |--- PostMsg.cshtml 
      |--- DeleteMsg.cshtml 

当我浏览的网址,如:

http://localhost/Comment/Manage/ --> return view successfully 
http://localhost/Comment/PostMsg --> error "The resource cannot be found." 

任何人有任何想法,为什么ASP MVC没有解决我的控制器:-(

,这里是我的global.asax.cs航线配置:

  routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

      routes.MapRoute(
       name: "Default", 
       url: "{controller}/{action}/{id}", 
       defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
       namespaces: new[] { "Demo.Web.Controllers" } 
      ); 

这里是我区登记航线配置:

 public override void RegisterArea(AreaRegistrationContext context) 
     { 
      context.MapRoute(
       "Comment_default", 
       "Comment/{controller}/{action}/{id}", 
       new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
       new[] { "Demo.Web.Areas.Comment.Controllers" } 
      ); 
     } 

问题:评论/ PostMsg URL被解析为在留言区域的控制器

目标:评论/ PostMsg URL被解析为CommentController的行动

任何帮助:-)

解决的问题,编辑区REGI理解共探路线配置(变通):

 public override void RegisterArea(AreaRegistrationContext context) 
     { 
      context.MapRoute(
       "Comment_default", 
       "Comment/PostMsg", 
       new { controller = "Comment", action = "PostMsg", id = UrlParameter.Optional }, 
       new[] { "Demo.Web.Controllers" } 
      ); 

      context.MapRoute(
       "Comment_default", 
       "Comment/{controller}/{action}/{id}", 
       new { controller = "Home", action = "Index", id = UrlParameter.Optional }, 
       new[] { "Demo.Web.Areas.Comment.Controllers" } 
      ); 
     } 

回答

3

你有行动指数** **中的PostMsgController Demo.Web.Areas.Comment.Controllers?据我了解,你从你的代码没有带

更新1

我thnik是/评论/ PostMsg - 可能是Demo.Web.Areas.Comment.Controllers

控制器PostMsgController你的行动指标

更新2

比你应该做

context.MapRoute(
    "Comment_default", 
    "Comment/PostMsg", 
    new { controller = "Comment", action = "PostMsg", id = UrlParameter.Optional }, 
    new[] { "Demo.Web.Controllers" } 
); 
+0

Ø f cos我有PostMsg操作:-(在视图\评论\文件夹中的PostMsg.cshtml :-( –

+0

对不起,在Demo.Web.Areas.Comment.Controllers – vlukham

+0

我不想推动区域内的PostMsg操作。 Comment.Controller.HomeController。我的目标是在CommentController中调用PostMsg操作:-) –