asp.net mvc - unusual behavior with attribute routing -
i working attribute routing , find excellent. in particular fact can localize routes in number of different cultures.
i have run in problem occurring irregularly - occurs , not others , can not find pattern.
the action method have is:
[get("/")] [get("{productid:int}")] [get("{category2id:int},{productid:int}/{category2slug}/{productslug}")] [get("{category2id:int},{category3id:int},{productid:int}/{category2slug}/{category3slug}/{productslug}")] [get("{category2id:int},{category3id:int},{category4id:int},{productid:int}/{category2slug}/{category3slug}/{category4slug}/{productslug}")] public virtual actionresult index(int productid, string productslug = null, string category2slug = null, string category3slug = null, string category4slug = null, int? category2id = null, int? category4id = null, int? category4id= null) and controller has next decorated on it
[sessionstate(sessionstatebehavior.disabled)] [routeprefix("product", translationkey = "product")] public partial class productcontroller and issue attribute rendering generate right url eg. https://localhost/product/22,33,999/cat2/cat3/product-name generates: https://localhost/product/999/?productslug=product-name&category2slug=cat2&category3slug=cat3&category2id=22&category3id=33
any thought why occuring , controller action params beingness added query string params , not part of url?
i working on , mvc4 application developed in c# version of attribute routing beingness 3.4.2.0.
any ideas?
you need order routes correctly. have it, there no guarantee of 5 routes comes first. can confirm visiting routes.axd.
what happens bugger urls route "{productid}" matched first, route params added querystring values. prepare this, la:
[get("product/{a}/{b}/{c}/{d}", actionprecedence = 1)] [get("product/{a}/{b}/{c}", actionprecedence = 2)] [get("product/{a}/{b}", actionprecedence = 3)] [get("product/{a}", actionprecedence = 4)] [get("product", actionprecedence = 5)] this helps url generation ordering routes specific least. if supply a, b, c, , d, the first route used url gen. if a,b, , c, sec used, etc....
asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing attributerouting
No comments:
Post a Comment