To add an Area to your MVC application right-click on the project and click "Add", then select "Area..."
Type in the word "Admin" in the "Add Area" dialog
Make sure AreaRegistration,RegisterAllAreas method is called in the Global.asax.cs file so that your "Admin" area is registered
The Areas folder structure should look like this.
Now we want to create a controller for the Admin Area, right-click "Controllers" folder under "Admin" and click "Add", then select "Controller"
Select and empty controller
Call the controller "HomeController", then click "Add"
Open the HomeController.cs file under the "Contollers" folder in the "Admin" folder, right-click on the "Index" method, then click "Add View"
Except the default options for the view and select "Add"
Open the Index.cshtml and type in the following code
@{ ViewBag.Title = "Index"; } <h2>Index</h2> <h1>This is from the Admin Area</h1>
Now if you type in the route /Admin/Home/Index you see the message "This is from the Admin Area"
Now comes the annoying part about Areas, when you type in the route /Home/Index you will get an error that the Home controller is not unique. That is because the MVC framework puts all controllers in finds in the application into a flat list regardless of namespace.
In order for us to fix this issue we need to specify the namespace in both the "AdminAreaRegistration.cs" file and RouteConfig.cs file
First let's fix the AdminAreaRegistration.cs file, open the file and type in the following code in the RegisterArea method
public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Admin_default", "Admin/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional }, new string[] { typeof(NorthwindCafe.Areas.Admin.Controllers.HomeController).Namespace } ); }
Notice in the last line new string[] { "NorthwindCafe.Areas.Admin.Controllers" } we set the namespace for the Admin Area controls so that MVC looks for the controllers that are only in that namespace
Now let's do the same thing for the RouteConfig.cs file. Open the RouteConfig.cs file and change the routes.MapRoute method to the following
routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new string[] {typeof(NorthwindCafe.Controllers.HomeController).Namespace} );
Now when you type in the route /Admin/Home/Index you see the Admin Index.cshtml page
And when you type in the /Home/Index route you see the application home page
Similar Posts:
- ASP.NET MVC: Change Admin URL to More User Friendly URL With Routing
- ASP.NET MVC; Get Rid Of The Port In The URL
The ISO code of Brazil is BR according to the ISO 3166 standard. The local name of the country is Brasil. Brazil capital city is Brasilia. People in Brazil speak the Portuguese language. On 7 September 1822, Brazil emerged as a sovereign political entity. In the year 09/07/1822, Brazil emerged as a sovereign political entity. The largest cities in Brazil are Brasília, Sao Paulo City, Rio de Janeiro, Salvador ; Sao Paulo, Rio de Janeiro, Belo Horizonte, Recife, Belém, Porto Alegre, Fortaleza;.
ReplyDeletehttp://www.confiduss.com/en/jurisdictions/brazil/
Mua vé máy bay tại Aivivu, tham khảo
ReplyDeletemua ve may bay di my
chuyến bay đưa công dân về nước
vé máy bay từ đức về việt nam giá rẻ
vé máy bay từ nhật bản về việt nam
Máy bay từ Hàn Quốc về Việt Nam
khi nào có chuyến bay từ canada về việt nam
vé máy bay chuyên gia sang Việt Nam