Click here to Skip to main content

Van Hua asked:

Open original thread
I'm newbie in asp mvc, currently, my demo project structure like this:
 
Areas -- Comment -- Controller -- HomeController
                               -- ManageController
Controller -- HomeController
          |-- CommentController
                     |____ PostMsg
                     |____ DeleteMsg
Views -- Home
     |     |--- Index.cshtml
     |-- Comment
           |--- PostMsg.cshtml
           |--- DeleteMsg.cshtml
When I browsing url like :
    http://localhost/Comment/Manage/ --> return view successfully
    http://localhost/Comment/PostMsg --> error "The resource cannot be found."
Anyone have any idea why asp mvc doesn't resolve my controller Frown | :-(
here is my global.asax.cs route config:
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" }
                );
here is my area registration route config:
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" }
                );
            }
Problem : Comment/PostMsg url was resolved as an Controller in Comment Area
 
Goal : Comment/PostMsg url was resolved as an Action of CommentController
Any help would be appreciated Smile | :)
 
ISSUE RESOLVED, edit area registration route config (work around):
 
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" }
            );
        }
Tags: C#, ASP, ASP.NET, MVC

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100