0
I have the following route:
routes.MapRoute(
"Contracts",
"Home/Contract/{contract}",
new
{
controller = "Home",
action = "Contract",
contract = UrlParameter.Optional
},
new { contract = @"\w+" }
);
It is possible to configure this route to receive both the controller
Home
(as already configured), how much for a new controller
calling for Contributor
? Basically an OR within the parameter controller
.
Why don’t you change the route to
"{controller}/Contract/{contract}",
?– Jéf Bueno
@LINQ but is the parameter controller that is inside the method Routes.Maproute?
– Leonardo Bonetti
@LINQ worked.... I just didn’t understand why, if I am declaring the controller = "Home", action = "Contract". If you can explain to me why it worked even with this statement I would appreciate.
– Leonardo Bonetti
The description of the third parameter of the Maproute method():
"An object that contains default value routes"
. When you give anew { controller = "Home" }
you are saying that if I do not pass any controller value in my url, it is for me to use a default value for that parameter, in which case it would be yoursHome
. If I pass some parameter with the controller value, I ignore this default value.– Gabriel Coletta
@Gabrielcoletta understood, thanks for the explanation, so just to see if I really understand... what counts even to set the route is the second parameter? in the case
"Home/Contract/{contract}",
?– Leonardo Bonetti
That’s where Gabriel spoke. The first parameter is the name of the route, the second is the format of it, the third are the standards.
– Jéf Bueno