I am trying to create a route constraint but not sure what would be the best for this. Here is the route with no constraint :
context.MapRoute(
"Accommodation_accomm_tags",
"accomm/{controller}/{action}/{tag}",
new { action = "Tags", controller = "AccommProperty" },
new { tag = @"" } //Here I would like to put a RegEx for not null match
);
What would be the best solution for this?
Why do you need a constraint for a not null/empty match? Normally if you define your route like this:
and
tagis not specified in the request url this route simply won’t match.And if you want a token to be optional, then:
Constraints are used when you want to constrain the value of a given route token to some specific format.