Guest User

Untitled

a guest
Jun 25th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. routes.MapRoute(
  2. "Id + Slug", // Route name
  3. "Test/{id}/{slug}", // URL with parameters
  4. new // Parameter defaults
  5. {
  6. controller = "Test",
  7. action = "Details",
  8. id = "",
  9. slug = ""
  10. },
  11. new { slug = new SlugConstraint() }
  12. );
  13.  
  14. public class SlugConstraint : IRouteConstraint
  15. {
  16. public bool Match(HttpContextBase httpContext,
  17. Route route,
  18. string parameterName,
  19. RouteValueDictionary values,
  20. RouteDirection routeDirection)
  21. {
  22. string value = values[parameterName].ToString();
  23.  
  24. return value.Contains("-");
  25. }
  26. }
Add Comment
Please, Sign In to add comment