开发者

Stringlength constraint for route?

I wa开发者_如何学编程s planning on having 2char language in url, like something.com/EN, /ES, /US. Is that possible to add a 2char constraint for a route?

/M


Yes u can do this by routeconstraints. constaints can be passed to Maproutes method in global.asax. if u have a constraint that can be handled by regex u can write it like

routes.MapRoute(
              "strict",
              "{controller}.mvc/{docid}/{action}/{id}",
              new {docid = "",action = "Index", id = ""},
              new { docid = @"\d+"}

            );

where regex pattern tells that docid should be numeric to match this route. however u can write ur own class that implements IRouteConstraint interface and object of that class can act as routeconstraint for ur route

take a look here to see how u can implement IRouteConstraint

ASP.NET MVC2 Parent Controller Not Redirecting

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜