0

I am trying to concatenate the c.name with Response.Write(counts[c.ID]);

Basically, in the <li>, I want it to be "Category name (x)".

So, basically shove the if statement after the c.name. How can this be done?

<li>
    <%:Html.ActionLink(c.Name, "Browse", "Listing", routes, null)%>
    <%
        if (showCounts && (bool)(ViewData["ValidCategoryCounts"] ?? true))
        {
            Response.Write("(");
            if (counts.ContainsKey(c.ID))
            {
                Response.Write(counts[c.ID]);
            }
            else
            {
                Response.Write("0");
            }
            Response.Write(")");
        }
    %>
</li>
GSerg
  • 76,472
  • 17
  • 159
  • 346
macecase
  • 147
  • 2
  • 12

1 Answers1

0

I would recommend building the full link text within the controller code. Alternatively you could use a helper within the view markup, such as the following example:

<%:Html.ActionLink(Html.GetNameWithCount(c.Name, counts), "Browse", "Listing", routes, null)%>
ollifant
  • 8,576
  • 10
  • 35
  • 45