01 August 2016 Sudhanshu Ranjan 581

set default page while using “Area” in MVC application

If you are using “Area” in your MVC application application then you should know that how to set the Default page in application using RouteConfig Class. Suppose you have multiple Controller with same Name (like Home Controller) in solution.

While set the default page or any routing you should be remember.

  1.  Add Namespace
  2.  Should be add “DataTokens” Properties.

 

 public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                namespaces: new string[] { "Portal.Areas.PortalAdmin.Controllers" }
            ).DataTokens.Add("Area", "PortalAdmin");
        }
    }

You can share at :

About Author
Sudhanshu Kumar Ranjan | Lead Engineer at HCL Technologies | Expertise in Microsoft Technology | Author | Blogger | Programmer
Know More
Connect with him on Facebook | Google+ | LinkedIn | Twitter

Recommended Post

Leave a comment

About Dotnet Cube

It's my blog - Dotnet Cube, where you will learn and get solutions about programming, web designing and development. I started this website to share my knowledge and experience which might help someone.

You can get more details about me and my blog at About Us page.

Subscribe Newsletter

Subscribe to our monthly newsletter to get the latest industry news, Media Group updates and our current specials.

Follow On Us...

Home | About | Advertise | Copyrights | Privacy | Contact | Admin

Copyrights © 2015-2017 dotnetcube.com. All rights reserved