Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- routes.MapRoute(
- "Id + Slug", // Route name
- "Test/{id}/{slug}", // URL with parameters
- new // Parameter defaults
- {
- controller = "Test",
- action = "Details",
- id = "",
- slug = ""
- },
- new { slug = new SlugConstraint() }
- );
- public class SlugConstraint : IRouteConstraint
- {
- public bool Match(HttpContextBase httpContext,
- Route route,
- string parameterName,
- RouteValueDictionary values,
- RouteDirection routeDirection)
- {
- string value = values[parameterName].ToString();
- return value.Contains("-");
- }
- }
Add Comment
Please, Sign In to add comment