HOW CAN I SET A ROUTE FOR A CONTROLLER WITHOUT A DEFAULT ACTION IN MVC 5?

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
 1359  View(s)
Ratings:
Rate this:
I have the following:
routes.MapRoute(
    "Account",
     url: "{controller}/{action}/{id}",
     defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
    );

However I don't want to specify a default action. Is there a way to do this for my MVC5 application?

  1. Ankita Pandey

    Post:183

    Points:1285
    Re: How can I set a route for a controller without a default action in MVC 5?

    Hey Ashish!

    You can try the below code.

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!