0

I have controller named PartialController and have a action method named AboutMe. I can access my action method from localhost/Partial/AboutMe . But i want to access it from localhost/About. So i changed my route like this:

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

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Blog", action = "Index", id =  UrlParameter.Optional }
        );

        routes.MapRoute(
        name: "About",
        url: "About",
        defaults: new
            {
                controller = "Partial",
                action = "AboutMe",
                id = UrlParameter.Optional
            }
        );

But i got 404 exception when trying to access AboutMe action from localhost/About. Need advice.

1 Answer 1

1

Define your About Route first. Order matters when it comes to routing, they are applied in the order in which they are defined.

  routes.MapRoute(
        name: "About",
        url: "About",
        defaults: new
            {
                controller = "Partial",
                action = "AboutMe",
                id = UrlParameter.Optional
            }
        );

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Blog", action = "Index", id =  UrlParameter.Optional }
        );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.