views:

37

answers:

2

I'd like to use the old school SiteMapPath in my MVC application how can I pass value to an attribute of the asp tag?

To be more precize I'd like to make the code below valid:

<asp:SiteMapPath 
      SiteMapProvider="Expression that returns ViewData["CurrentSiteMapProvider"]" 
      ID="SiteMapPath" runat="server"/>
A: 

Something like this should work:

<asp:SiteMapPath 
  SiteMapProvider='<%# ViewState["CurrentSiteMapProvider"] %>' 
  ID="SiteMapPath" runat="server"/>

You need a DataBind somewhere in the page. Also note that you need to use apostrophes not quotes around the data binding expression.

Edit: I assume that by ViewData you mean ViewState. If not just adjust what's inside the <%# and %>.

rslite
I meant ViewData, ViewState isn't available in asp.net MVC as far as i know. But let me try your solution
Piotr Czapla
It doesn't work :(. It looks like it doesn't recognize ViewData
Piotr Czapla
OK, I answered this more from an ASP.NET point of view. I don't have experience with MVC, but I thought it would work in the same way. Can you replace that with a property and see if it can be read in the page?
rslite
ViewData["CurrentSiteMapProvider"] is accessible in the page. I finally chosen to write my own implementation of site map path.
Piotr Czapla
A: 

I finally decided to rewrite the breadcrumb as html helper method. It took me 15 min to get it right and now I have full control over the html.

Piotr Czapla