Areas

Other topics

Remarks:

if you want to go to this area through your default controller

      return RedirectToAction("Index","Home",new{area="areaname"});

Create a new area

Right click on your project folder/name and create new area and name it.

In mvc internet/empty/basic application a folder with the name of the area will be created,which will contain three different folders named controller , model and views and a class file called

"areanameAreaRegistration.cs"

Configure RouteConfig.cs

In your App_start folder open routeconfig.cs and do this

 routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            namespaces:new []{"nameofyourproject.Controllers"}// add this line ;
        );

Create a new controller and configure areanameAreaRegistration.cs maproute

Create a new controller foreg

ControllerName: "Home", ActionresultName :"Index"

open AreaRegistraion.cs and add the controller name and action name to be rerouted to

    context.MapRoute(
            "nameofarea_default",
            "nameofarea/{controller}/{action}/{id}",  // url shown will be like this in browser
            new {controller="Home", action = "Index", id = UrlParameter.Optional }
        );

Contributors

Topic Id: 6310

Example Ids: 21795,21796,21797

This site is not affiliated with any of the contributors.