0

对 ASP.NET 来说相当新,并试图弄清楚如何让代码回显它获取的信息。

<ul class="accordion">
    <% foreach (var cat in Model.Categories.Where(x=>x.ParentId==null).OrderBy(x=>x.DisplayOrder).ThenBy(x=>x.CategoryName)) { %>
        <li style="height: auto; min-height:30px;">
            <%= Html.ActionLink(cat.CategoryName, "Index", "Products", new { id=cat.UniqueName, area="" }, null)%>

            <%if(cat.SubCategories.Count>0) {%>
                <ul class="sub-menu" style="font-size:.8em; padding-left:20px;">
                    <% foreach (var c in cat.SubCategories) { %>
                        <li><%= Html.ActionLink(c.CategoryName, "Index", "Products", new { id=c.UniqueName, area="" }, null)%></li>
                    <% } %>
                </ul>
            <%}%>
        </li>
    <%} %>
</ul>

目前我知道它与<%= Html.ActionLink(cat.CategoryName, "Index", "Products", new { id=cat.UniqueName, area="" }, null)%>那条线有关,但不知道如何让它传递信息。可能是一个愚蠢的问题,但谷歌在搜索这个答案时绝对没有帮助。

谢谢。

4

1 回答 1

0

以下是一些命令的简要概述:

 <%= Html.ActionLink(cat.CategoryName, "Index", "Products", new { id=cat.UniqueName, area="" }, null)%>

将创建:

 <a href="products/index/{UniqueName}">{CategoryName}</a>

也可以构造为:

 <a href="<%= Url.Action("Index", "Products", new { id=cat.UniqueName, area="" })%>"><%: cat.CategoryName%></a>

这还将创建:

 <a href="products/index/{UniqueName}">{CategoryName}</a>

因此,您可以使用以下命令仅输出名称或 ID:

 <%: cat.CategoryName %>

或者

 <%= cat.CategoryName %>

<%= 是 "Response.Write" 和 "<%:" 是 Response.Write 与 HTML 编码

于 2012-05-22T14:53:05.300 回答