can I have a route like…
routes.MapRoute(
"Boundaries-Show",
"Boundaries",
new
{
controller = "Boundaries",
action = "Show",
locationType = UrlParameter.Optional
});
Where the action method is…
[HttpGet]
public ActionResult Show(int? aaa, int? bbb, LocationType locationType) { ... }
and if the person doesn’t provide a value for locationType .. then it defaults to LocationType.Unknown.
Is this possible?
Update #1
I’ve stripped back the action method to contain ONE method (just until I get this working). It now looks like this ..
[HttpGet]
public ActionResult Show(LocationType locationType = LocationType.Unknown) { .. }
.. and I get this error message…
The parameters dictionary contains an
invalid entry for parameter
‘locationType’ for method
‘System.Web.Mvc.ActionResult
Show(MyProject.Core.LocationType)’ in
‘MyProject.Controllers.GeoSpatialController’.
The dictionary contains a value of
type ‘System.Int32’, but the parameter
requires a value of type
‘MyProject.Core.LocationType’.
Parameter name: parameters
Is it thinking that the optional route parameter LocationType is an int32 and not a custom Enum ?
You can supply a default value like so:
UPDATE:
Or if you are using .NET 3.5:
UPDATE 2: