-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Route attribute not working with area routes #446
Comments
I am unable to reproduce the behavior you describe. Here is a project demonstrating that the The behavior of the route attribute is meant to be exactly the same as using It is possible that your routing is misconfigured. See this question as well as this question for some common routing pitfalls. |
Ok, first wouldn't it be a better idea to use the route attribute to takeover the way the route is configured?! Second, I think I know where the issue is .... My configured routes looks like: Is it possible that the fixed name "List" is an issue here? |
Perhaps in a future version, it might be possible to extend MVC routing to add the parent-child relationship and title that routing is missing in order to configure
On the contrary. Adding fixed values to the URL is one of the ways to make a route unique so routing works correctly. These fixed values affect the matching of the incoming URL and the building of the outgoing URL only. They do not affect the route values that are generated by the route (which are what RoutingI believe one problem is that you are putting a constraint on an optional value. I tried doing that before, but was unable to make it function and I am pretty sure routing is not designed to work that way. An alternative way to configure it would be to make 2 different routes to replace your optional Do note that making context.MapRoute(
"Crm_Contacts_List_Sort",
"Crm/Contacts/List/{group}/{sort}",
new { controller = "Contacts", action = "Index" },
new { sort = "^Company_Asc$|^Company_Desc$|^Lastname_Asc$|^Lastname_Desc$" }
);
context.MapRoute(
"Crm_Contacts_List",
"Crm/Contacts/List/{group}",
new { controller = "Contacts", action = "Index", group = "Alle" }
); I am not sure if this is exactly right for your use case, though. If it doesn't make sense to have a "default" group at all, then you should make it required by not supplying a default. context.MapRoute(
"Crm_Contacts_List_Sort",
"Crm/Contacts/List/{group}/{sort}",
new { controller = "Contacts", action = "Index" },
new { sort = "^Company_Asc$|^Company_Desc$|^Lastname_Asc$|^Lastname_Desc$" }
);
context.MapRoute(
"Crm_Contacts_List",
"Crm/Contacts/List/{group}",
new { controller = "Contacts", action = "Index" }
); Usually, the right way to configure routing is to use required URL parameters, not optional parameters. The typical case is to make 1 URL map to an action. Using optional parameters makes multiple URLs map to an action (unless the alternates are explicitly suppressed using In my first example,
In the second example, it only matches NodesAs for your node configuration, it is not matching in this case because the node is missing matching route values for <mvcSiteMapNode title="$resources:Sitemap,Contacts_Title" area="Crm" controller="Contacts" action="Index" preservedRouteParameters="group,sort" visibility="CrmMenu,CrmBreadcrumb,!*" /> If If <mvcSiteMapNode title="$resources:Sitemap,Contacts_Title" area="Crm" controller="Contacts" action="Index" group="Group1" preservedRouteParameters="sort" visibility="CrmMenu,CrmBreadcrumb,!*" />
<mvcSiteMapNode title="$resources:Sitemap,Contacts_Title" area="Crm" controller="Contacts" action="Index" group="Group2" preservedRouteParameters="sort" visibility="CrmMenu,CrmBreadcrumb,!*" />
<mvcSiteMapNode title="$resources:Sitemap,Contacts_Title" area="Crm" controller="Contacts" action="Index" group="Group3" preservedRouteParameters="sort" visibility="CrmMenu,CrmBreadcrumb,!*" /> See How to Make MvcSiteMapProvider Remember a User's Position for a detailed explanation of these options and how they work. |
First of all - thank you very much for your detailed explanation which gets me a little bit further. My configuration now looks like the following: context.MapRoute(
"Crm_Contacts_List_Sorted",
"Crm/Contacts/List/{group}/{sort}",
new { controller = "Contacts", action = "Index", group = "", sort = UrlParameter.Optional },
new { sort = "^Company_Asc$|^Company_Desc$|^Lastname_Asc$|^Lastname_Desc$" }
);
context.MapRoute(
"Crm_Contacts_List",
"Crm/Contacts/List/{group}",
new { controller = "Contacts", action = "Index", group = "" }
); and the XML configuration like: <mvcSiteMapNode title="$resources:Sitemap,Contacts_Title" route="Crm_Contacts_List" controller="Contacts" action="Index" visibility="CrmMenu,CrmBreadcrumb,!*" /> The resulting link looks like the following: If I now can get rid of the URL parameter area it would be perfect suited. |
When using the route attribute in XML configuration for a defined area route it seems to be ignored. Is that by design and would I need to use an external DI or is it a bug?
The text was updated successfully, but these errors were encountered: