Mapping to Details Page

Jul 29, 2010 at 2:57 PM
Edited Jul 29, 2010 at 3:03 PM

Hi, i'm trying to display the site map path for a page which has some additional route values (such as the id for a details page). Here is my site map:

<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-2.0" enableLocalization="true">
  <mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal">
    <mvcSiteMapNode title="Users" controller="Users" action="Index">
    <mvcSiteMapNode title="View User" controller="Users" action="Details" />
    <mvcSiteMapNode title="New User" controller="Users" action="Create" />
  </mvcSiteMapNode>
</mvcSiteMap>

I then have <%= Html.MvcSiteMap().SiteMapPath() %> within my master page. I have read the documentation found at http://mvcsitemap.codeplex.com/wikipage?title=Action%20Filter%20Attributes&referringTitle=Home and tried doing:

[SiteMapTitle("UserName")]
public ActionResult Details(int id) {
  return View(_repository.GetByID(id));
}

When i navigate to /Users and /Users/Create the correct site map path is display. But going to the details (eg /Users/Details/1) doesn't display anything.

I've also looked at the http://mvcsitemap.codeplex.com/wikipage?title=Dynamic%20sitemaps&referringTitle=Home article but this seems like a very tedious task if i want to do this for every details page. I'd appreciate it if someone could show me what i am doing wrong. Thanks

Coordinator
Jul 30, 2010 at 6:25 AM

The above should work nicely. Is the routing table modified or just the default route from ASP.NET MVC?

Jul 30, 2010 at 8:30 AM

Cheers for the reply but no i haven't changed the routing.  It seems to be the id parameter that's causing the issue.  This is the one stumbling block for me otherwise this library looks great.

Coordinator
Jul 30, 2010 at 12:33 PM

Does it work if you remove the [SiteMapTitle] ?

Jul 30, 2010 at 6:48 PM

Hey nope, i'm sure i've configured everything correctly to my knowledge.  When i initialized my site map in the web.config file i set security trimming to true but i've tried removing this and it did not make a difference either.  It seems as though this is a bug v2.  I'd appreciate it once more if you could help.  Thanks

Aug 10, 2010 at 4:42 PM
Edited Aug 10, 2010 at 4:43 PM

Any movement on this issue? I'd like to use the sitemap library, but mapping urls to action parameters is a stumbling block for me. Static urls work fine, but cannot figure out how to get something like an {id} parameter to map properly. I've look at the dynamic node extension points, but the examples seem to use only an unparameratized query to grab a list of products. Is there a way to specify what the {id} would be? (eg. If the user is viewing a specific customer record, I need something like "Customer/Edit/{id} where {id} is the value of the current customer.ID)

Coordinator
Aug 11, 2010 at 6:20 AM

Can you try the 2.2.0 branch code and add the [SiteMapPreserveRouteData] attribute to this action method?

Aug 12, 2010 at 8:36 PM

Hi, I can't test this at the moment as I'm receiving the error I mentioned here.  I've tried with and without the SiteMapPreserveRouteData attribute but the problem remains for both.  I appreciate your help so far.

Nov 17, 2010 at 11:21 AM

I've the same problem - for me it seems to be a problem connected with caching and SiteMapPreserveRouteData because every time i change web.config on working server it take some time to "refresh" but it works on detail page (with id) but without showing detailed parameter. It works after some time (5 minutes) too still without showing detailed parameter.

Coordinator
Nov 18, 2010 at 6:04 AM

Whcih version are you using?

Nov 20, 2010 at 11:57 AM
Edited Nov 20, 2010 at 11:58 AM

actual 2.2.1 and previous

from the behavior i can deduct that provider somehow sees only one "configuration" of parameters

first start of app

controller/Edit/id - display empty string

controller/Edit - (without id that's of course incorrect) display correct title

some change in web.config to invalidate mvcsitemap (tests in reverse order)

controller/Edit/id - display correct title but without parameters

controller/Edit - display empty string

 

I've make some checks to SiteMap.CurrentNode in On Action Execute and provider returns nulls for situations described above. I've been using special attribute SiteMapPreserveRouteData and my own similar solution in On Action Execute which does the same and which was working in 1 version of mvcsitemap but now is useless because of null in SiteMap.CurrentNode so i'm unable to copy attributes from action to sitemap node.

 

Coordinator
Nov 22, 2010 at 6:15 AM

Can you post a small project that reproduces this behaviour?