-
Notifications
You must be signed in to change notification settings - Fork 218
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
Using MVC SiteMapProvider and DynamicNodeProvider in MVC site for CRUD operations, DynamicNode gets wrong text #135
Comments
Have the same issue. Appreciate if smb can solve it. |
I just solved a similar issue in the new version. The dynamic node building logic first tries to use the parent ID that you provide, and then falls back to some default logic (which apparently doesn't always work). If you set the ParentKey manually, you should be able to get the relationship to work. Here is the way it is done in the MvcMusicStore demo: public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
{
// Create a node for each album
foreach (var album in storeDB.Albums.Include("Genre"))
{
DynamicNode dynamicNode = new DynamicNode();
dynamicNode.Title = album.Title;
dynamicNode.ParentKey = "Genre_" + album.Genre.Name;
dynamicNode.RouteValues.Add("id", album.AlbumId);
if (album.Title.Contains("Hit") || album.Title.Contains("Best"))
{
dynamicNode.Attributes.Add("bling", "<span style=\"color: Red;\">hot!</span>");
}
yield return dynamicNode;
}
} |
Hi! I tried today your sollution, but it doesn't seem to fit with my problem. Notice that I don't have a parent. My mvc.sitemap file is declared as: <mvcSiteMapNode title="Inicio" controller="Home">`
<mvcSiteMapNode title="Equipo" controller="Equipo">
<mvcSiteMapNode title="Crear Equipo" action="Create"></mvcSiteMapNode>
<mvcSiteMapNode title="Detalle Equipo" action="Details" dynamicNodeProvider="MvcApplication2.TestDynamicNodeProvider, MvcApplication2" preservedRouteParameters="id">
<mvcSiteMapNode title="Editar Equipo" action="Edit" ></mvcSiteMapNode>
<mvcSiteMapNode title="Eliminar Equipo" action="Delete"></mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMapNode>
</mvcSiteMapNode> Notice like edit and delete actions are nested inside details (since I can only go to these throught the details action first). Beside this, based on an answer to my question posted on stackoverflow.com, I have added the preservedRouteParameters option, which now builds the link fine, but the text is still wrong. I attach a new screenshot: |
@farlop |
As far as I am aware, the only node that can exist with no parent is the root node. All of the other logic assumes every node below it will have a parent otherwise the node cannot be correctly found within the map. If that is what is happening in your case, it would explain why the text is not correct - FindSiteMapNode is not returning the correct result. |
OK. After taking a deep breath I've done some meditation about what I'm trying to achieve. The real problem I had was about the wrong url generated in the SiteMap. This was due to the missing 'preservedRouteParameters' attribute. So, once this is solved, the only thing remaining is how to swap the default "Detalle Equipo" text that appears in the details node to use a custom label ("Tronzadora"). So maybe this is not about generating dynamic nodes for diferent records (as in musicstore)... any idea about how to achieve this? |
If it is in the topmost node you need the title for, there is a SiteMapTitleAttribute that can be used for this purpose. See the MvcMusicStore demo in the repo for an example how to use it. If not, check out issue #45 for a custom implementation of a Title Provider. This isn't built in, but I am seriously considering adding this as a feature of v4 when I get a chance. But if you need to have it sooner, you can implement it yourself using the VisibilityProvider as a template. |
This functionality is just what I need! I expect to see it in the future v4. Meanwhile, I will try to implement it by myself. Thanks a lot for helping me to understand better how MvcSiteMapProvider works. |
Ok, I will add this to v4 when I get a chance. I was trying to think of a way to make it more useful - like being able to override any property, not just title. Thus far, I haven't thought of a good way to implement it like that though. |
When implementing a DynamicNodeProvider like this:
Breadcrumbs shows always the first element in collection instead of current one. See an example below:
Breadcrumb should be "Inicio > Equipo > TRONZADORA > Editar Equipo", but it shows TALADRO insteadm, which is the first item in collection (link also is wrong!).
The text was updated successfully, but these errors were encountered: