Can I constrain a route parameter to a certain type in ASP.net MVC?
问题 I have the following route: routes.MapRoute( "Search", // Route name "Search/{affiliateId}", // URL with parameters new { controller = "Syndication", action = "Search" } // Parameter defaults ); Is there a way I can ensure "affiliateId" is a valid Guid? I'm using MVCContrib elsewhere in my site and I'm fairly it provides a way to implement this kind of constraint.... I just don't know what it is! 回答1: You could write regex constraints: routes.MapRoute( "Search", // Route name "Search/