0

I have a area register routing:

public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "MyArea_default",
            "MyArea/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "market.Areas.MyArea.Controllers" }
        );
    }

Its working as this, its ok:

localhost:MyArea/ActionName

But I hit F5 (in visual studio) when selected a specific view then url is:

localhost:MyArea/Home/ActionName

So how can work without controller name in url, when I hit f5 if a specific view selected?

2 Answers 2

1

What I understand from your code:

localhost:MyArea/ActionName => Will use homeControllerClass with ActionName method.

localhost:MyArea/Home/ActionName => Will not work since it uses homeControllerClass but with ActionName "Home" !! That is it is looking for home method in homeControllerClass.

From you code: "MyArea/{action}/{id}" new { controller = "Home", action = "Index", id = UrlParameter.Optional }

=> It implies to use the homecontroller class for requests of MyArea with default action name of index if no action is specified. So if you use MyArea/Home => it will use homeController but with action "Home".

{Controller}/{Action}

Sign up to request clarification or add additional context in comments.

Comments

0

The simplest solution is to use the costume route attribute.

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.