I have an ASP.Net application that has an area called Clients. In this area, there is a controller with the same name using a single Index method.
I defined the following route:
context.MapRoute(null,
"Customers/{controller}/{action}",
new { controller = "customers", action = "Index" }
);
This allows me to go to the following URL to go to the index method on my client controller.
MYDOMAIN / Customers
In my client area, I also have another controller called a product. This has several methods that allow me to work with product objects (mostly automatically generated by Visual Studio at the moment).
With my current route, I can go to the product controller using the following URL:
MyDomain// ( ) MyDomain/// ( ). MyDomain///? Id = 1234 ( 1234)
, , - URL-, :
MyDomain///1234
, :
context.MapRoute(null,
"Customers/Products/{id}",
new { controller = "Products", action = "Details" }
);
.
, , .
. URL
MyDomain///
:
'id' of non-nullable type 'System.Int32' 'System.Web.Mvc.ViewResult (Int32)
, , URL- .
:
context.MapRoute(null,
"Customers/Products/{id}",
new { controller = "Products", action = "Details", id = UrlParameter.Optional }
);
.
- , , , ? :
- "", , URL- "MyDomain/Customers"
- , , URL- "MyDomain/Customers/Products/1234".
- , , URL- "MyDomain/Customers/Products/Create"