Up vote 0 down vote favorite share g+ share fb share tw.
I am having some real "fun" times with ASP. NET MVC outgoing URL/link generation. Trying to get a clean looking URL link schema going with some unexpected results to boot and yes I am aware that ASP.
NET routing engine will try to find values for all segements of a matching route, this includes reusing values from the request context if said values were not specified with matching anonymoys types in the URL\link generating helper methods or in the routes themselves. The page in question contains a three level nav menu and some back and forward page links. The goal: Navmenu Root: mysite.com/cats mysite.com/dogs mysite.com/birds paging links should be: mysite.com/cats/1 ..... Navmenu 1st level mysite.com/cats/food mysite.com/dogs/food mysite.com/birds/food paging links should be: mysite.com/cats/food/1 Navmenu 2nd level mysite.com/cats/food/canned mysite.com/dogs/food/frozen mysite.com/birds/food/canned paging links should be: mysite.com/cats/food/canned/1 The URL's for the links are generated as follows: NavMenu (Just showing the rootlevel link generation) @Url.
Action("Index", "Store", new { RootPointer = @RootCat. CatName}) Paging (This one should generate for all levels) @Url. Action("Index", "Store", new { page = (@Model.PagingInfo.
CurrentPage + 1)}) The routes (Only going to include the ones for handling root cat URL's for NavMenu and paging and they will tell the problem for the rest, which just increment with {L1Cat}/{L2Cat} etc.) routes. MapRoute( "Store1", // Route name "{RootPointer}", // URL with parameters new { controller = "Store", action = "Index", }, new { controller = "Store", action = "Index" }); routes. MapRoute( "Store1p", // Route name "{RootPointer}/{page}", // URL with parameters new { controller = "Store", action = "Index", }, new { controller = "Store", action = "Index", page = @"\d+" }); The results Now depending in which order the above routes are placed the produced URL's of course vary.
In order shown produces the following: The root menu links work correctly And mysite.com/cats etc. root navmenu links will remain as such nomatter which level I am on. The paging however stuffs up because it latches onto the first route without the page url segment and the link produced looks like so: mysite.com. Cats?
Page=2 Should I reverse the routes the problem reverses. Now page links are correct but all root level menu links render as mysite.com/cats/1 etc. Also I don't understand why but when I define a more specific route as below above the others, with or without contraints routes. MapRoute( "Store3", // Route name "{RootPointer}/{L1Cat}/{L2Cat}", // URL with parameters new { controller = "Store", action = "Index", L1Cat = UrlParameter.
Optional, L2Cat = UrlParameter. Optional }, new { controller = "Store", action = "Index" , L1Cat = @". *^\d.
*", L2Cat = @". *^\d. *"}); Then say select from the NavMenu Cats>Food this will then force only the /Cats NavMenu root level link, initialy /Cats to change to /Cats/Food.
This is contrary to what I read about how the routing system re-uses values from the request context, which stated only earlier segments of the route in respect to the provided segment value position will be populated with values from the request context. I am providing a value for {RootPointer} in my helper methods (earliest/first value), hence I don't see how it makes /Cats root link into /Cats/Food if I click on Cats>Food and why only the parent of the link that was clicked on and not all the others parent/root level links. When defining one main route as such: routes.
MapRoute( "MainRoute", // Route name "{RootPointer}/{L1Cat}/{L2Cat}/{page}", // URL with parameters new { controller = "Store", action = "Index", RootPointer = UrlParameter. Optional, L1Cat = UrlParameter. Optional, L2Cat = UrlParameter.
Optional, page = UrlParameter. Optional }, new { controller = "Store", action = "Index"}); This will cause page numbers to be assigned to L1Cat or L2Cat etc. when without constraints and not work with constraints as they then override the UrlParameter. Optional and route has too many segments for all lower level URL requests.
Asp.net asp. Net-mvc asp. Net-mvc-3 asp.
Net-mvc-routing link|improve this question edited Mar 13 at 22:28 asked Mar 13 at 22:05LaserBeak52119 74% accept rate.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.