我认为这是我从 asp.net 和后面的 C# 代码生成的 HTML 的问题。本质上,我使用 ListView 生成 SmartAdmin 导航,该 ListView 的代码背后的函数绑定到它的 OnItemDataBound 函数。
<asp:ListView OnItemDataBound="lvwMenu_ItemDataBound" ID="lvwMenu" runat="server" >
<LayoutTemplate>
<nav>
<!--
NOTE: Notice the gaps after each icon usage <i></i>..
Please note that these links work a bit different than
traditional href="" links. See documentation for details.
-->
<ul>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</ul>
</nav>
</LayoutTemplate>
<ItemTemplate>
<li class="<%# If(Container.DataItemIndex.Equals(0), "active", "")%>">
<asp:PlaceHolder ID="pnlAnchorAll" runat="server">
<a id="lkbtnData" runat="server" title='<%# Bind("Description")%>'>
<i class="fa fa-lg fa-fw <%# DataBinder.Eval(Container.DataItem, "Label") %>"></i> <span class="menu-item-parent"><%# DataBinder.Eval(Container.DataItem, "Description")%></span>
<%-- Repeater is here generating second level of pages --%>
</a>
</asp:PlaceHolder>
</li>
</ItemTemplate>
</asp:ListView>
这是函数背后的 DataBound 事件代码:
Protected Sub lvwMenu_ItemDataBound(sender As Object, e As ListViewItemEventArgs)
If e.Item.ItemType = ListViewItemType.DataItem Then
Dim rowView As DataRowView
rowView = DirectCast(e.Item.DataItem, DataRowView)
Dim lkbtnData As HtmlAnchor, pnlAnchorAll As PlaceHolder, rptSubMenu As Repeater
If rowView("Description").ToString().Equals("Second Level", StringComparison.OrdinalIgnoreCase) Then
rptSubMenu = DirectCast(e.Item.FindControl("rptSubMenu"), Repeater)
oBSAOM = New MD.bsAOM(_oSession:=Session)
oBSAOM.bGetSecondLevel("Pages", rptSubMenu)
lkbtnData.HRef = "javascript:void(0)"
Else
lkbtnData.HRef = rowView("Value").ToString()
End If
End If
End Sub
我正在使用转发器生成第二级页面
<asp:Repeater ID="rptSubMenu" runat="server">
<HeaderTemplate>
<ul class="">
</HeaderTemplate>
<ItemTemplate>
<li>
<a id="lkbtnSubData" runat="server" title='<%# Bind("Description")%>' href='<%# Bind("Value")%>'>
<i class="fa fa-fw fa-folder-open"></i> <%# DataBinder.Eval(Container.DataItem, "Description")%>
</a>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
输出到浏览器时生成的源是:
<nav>
<!--
NOTE: Notice the gaps after each icon usage <i></i>..
Please note that these links work a bit different than
traditional href="" links. See documentation for details.
-->
<ul>
<li class="active">
<a href="Home.aspx" id="ctl00_lvwMenu_ctrl0_lkbtnData" title="Home">
<i class="fa fa-lg fa-fw fa-home"></i> <span class="menu-item-parent">Home</span>
</a>
</li>
<li class="">
<a href="javascript:void(0)" id="ctl00_lvwMenu_ctrl5_lkbtnData" title="Second Level">
<i class="fa fa-lg fa-fw fa-dollar"></i> <span class="menu-item-parent">Second Level</span>
<!-- BEGIN Second Level Example here -->
<ul>
<li>
<a href="../SecondLevel/Page.aspx" id="ctl00_lvwMenu_ctrl5_rptSubMenu_ctl01_lkbtnData" title="2nd Level Page">
<i class="fa fa-fw fa-folder-open"></i> 2nd Level Page
</a>
</li>
</ul>
<!-- END Second Level Example here -->
</a>
</li>
</ul>
</nav>
这看起来是正确的。但是页面加载时立即发生的事情是源被修改(我认为是 SmartAdmin 的 JS):
<li>
<a title="Second Level" id="ctl00_lvwMenu_ctrl5_lkbtnData" href="javascript:void(0)">
<i class="fa fa-lg fa-fw fa-dollar"></i> <span class="menu-item-parent">Second Level</span>
<b class="collapse-sign"><em class="fa fa-plus-square-o"></em></b>
</a>
<!-- BEGIN Second Level Example here -->
<ul style="display: none;">
<a title="Second Level" id="ctl00_lvwMenu_ctrl5_lkbtnData" href="javascript:void(0)"> <!-- Anchor Tag is incorrectly generated here -->
</a>
<li>
<a title="Second Level" id="ctl00_lvwMenu_ctrl5_lkbtnData" href="javascript:void(0)"> <!-- Anchor Tag is incorrectly generated here -->
<a title="Page" id="ctl00_lvwMenu_ctrl5_rptSubMenu_ctl01_lkbtnSubData" href="../SecondLevel/Page.aspx">
<i class="fa fa-fw fa-folder-open"></i> Page
</a>
</li>
</ul>
<!-- END Second Level Example here -->
</li>
以前有没有人遇到过类似的问题?