Hi, Everybody!
For some reason in our site we need use "Default" MapRoute such as this:
routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); and in "SpecRoute" MapRoute such as this:
routes.MapRoute( "SpecRoute", // Route name "SPEC{sId}/{controller}/{action}/{id}", // URL with parameters new { controller = "Spec", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); The second Maproute as well as first maproute describes some controlles (1-st maproute: Home, Help, Goods, etc; 2-nd maproute: Spec, Details, Pays, etc.).
I have next issue: I want to specify in Menu (sitemap or somewhere else) the routemap name to generate url with. For example:
for 1-st maproute url must look like this: http://server/Home, http://server/Help/Article/23, http://server/Goods/Item/50
for 2-ndmaproute url must look like this: http://server/SPEC56/Details/, http://server/SPEC56/Details/Pays/267, etc.
Can anybody help me resolve or reject us impossible?
Thanks a lot for attention.
Yevhenii
6 Answers, 1 is accepted
The ASP.NET routing should work correctly when you specify the right controller and action. This means that the right URL should be returned and used by the menu component.
Of course I may not be getting your requirements. You can attach a simple running project which shows the case.
Atanas Korchev
the Telerik team
Hi, Atanas!
Well. I couldn't attach a simple project.
Below is more describes of issue.
We have 2 MapRoutes ("Default" and "Spec"). When we navigating over "Default" MapRoute we don't have an issue. (Myabe becuase we don't show part of menu for "Spec" MapRoute). But when we go by URL like "http://server/SPEC56/Details/Pays/267" in menu we have got next URLs: http://server/SPEC56/Home instead http://server/Home, http://server/SPEC56/Help/Article/23 instead http://server/Help/Article/23, http://server/SPEC56/Goods/Item/50 instead http://server/Goods/Item/50, etc.
(btw http://server/SPEC56/Goods/Item/50 work same as well as http://server/Goods/Item/50, but it look not very good)
Regards,
Yevhenii
Unfortunately I cannot understand the exact case without some code. Perhaps if you manage to create a sample project we would be able to help.
Regards,Atanas Korchev
the Telerik team
Hi, Atanas!
Please, find in attachment sample project.
Do next:
- run project
- go by links "About", "Register" and look after URL in browser. (http://localhost:64418/Home/About, etc.)
- go by link "Special link" and check URL (http://localhost:64418/SPEC98/Special/Action/23)
- go again by link "About" and check URL (http://localhost:64418/SPEC98/Home/About). It looks a bit wrong. must be like "http://localhost:64418/Home/About"
Regards,
Yevhenii.
The aforementioned behavior is expected. Url.Action is used to build url for each MenuItem. Url.Action will use first matched Route, which will cause the issue. I will suggest you use this code snippet to overcome this problem:
... .BindTo("DefaultSiteMap", (item, siteMapNode) => { item.Url(Url.RouteUrl("default",new { action = siteMapNode.ActionName, controller = siteMapNode.ControllerName }));...Regards,
Georgi Krustev
the Telerik team
Thank you very much for your help
Regards, Yevhenii.