I have a question about MVC routing. Given the route:

routes.MapRoute(
    name: "Venda",
    url: "{controller}/{action}/{automovelId}/{consumidorId}/{revendedoraId}",
    defaults: new {
        controller = "Venda",
        action = "Index",
        automovelId = UrlParameter.Optional,
        consumidorId = UrlParameter.Optional,
        revendedoraId = UrlParameter.Optional
    }
);

I want to be able to call the Edit action like this:

/Venda/Edit/1/1/1

But it only works when called like this:

/Venda/Edit?automovelId=1&consumidorId=1&revendedoraId=1

How can I do this?

有帮助吗?

解决方案

You cant use multiple optional parameters in a route. Only the last parameter can be optional.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top