简体   繁体   English

如何将viewdata属性放入asp标签的属性中

[英]How to put viewdata attribute in to property of asp tag

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? 我想在我的MVC应用程序中使用老式的SiteMapPath,如何将值传递给asp标签的属性?

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"/>

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. 编辑 :我认为通过ViewData的意思是ViewState。 If not just adjust what's inside the <%# and %>. 如果不是,只需调整<%#和%>中的内容。

I finally decided to rewrite the breadcrumb as html helper method. 我最终决定将面包屑重写为html helper方法。 It took me 15 min to get it right and now I have full control over the html. 我花了15分钟将其正确设置,现在我可以完全控制html了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM