tags:

views:

123

answers:

1

Why does this code produce these results?

CODE:

    <%@ Control Language="C#" 
            Inherits="System.Web.Mvc.ViewUserControl< RoomsAlive.ViewModels.ProductCatalogViewModel >" %>

<div id="product_nav">
    <ul>
    <%--ADD PREV TAB--%>
    <% if (Model.HasPreviousPage) %>
    <% { %>
        <li><%= Html.RouteLink("<<", "CatalogMenu", new { controller = "Catalog", action = "Index", style = (Model.GroupName), position = (Model.PageIndex - 1) })%></li>
    <% } %>
    <%--LOOP HERE--%>
    <%  foreach (RoomsAlive.Models.ProductMenuView myFPV in Model.ProductMenu)
        { %>
        <li><%= Html.RouteLink(myFPV.Name, "CatalogMenu", new { controller = "Catalog", action = "Index", group = Model.GroupName })%></li>
    <%  } %>
    <%--ADD NEXT TAB--%>
    <% if (Model.HasNextPage) %>
    <% { %>
        <li><%= Html.RouteLink(">>", "CatalogMenu", new { controller = "Catalog", action = "Index", position = (Model.PageIndex + 1) })%></li>
    <% } %>
    </ul>
</div>

RESULTS:

<div id="product_nav">
    <ul>
        <li><a href="">LifeStyle</a></li>
        <li><a href="">Rooms</a></li>
    </ul>
</div>

BTW: If I use the <% %> form instead of the <%= %> form it produces this:

<div id="product_nav">
    <ul>
        <li></li>
        <li></li>
    </ul>
</div>
+1  A: 

Why are you specifying the controller and action in the object part of the Actionlink?

Wouldn't it be best to do it this way:

<%= Html.RouteLink("<<", "Index", "Catalog", new { style = Model.GroupName, position = (Model.PageIndex - 1) }, null)%>

The second property of ActionLink is always the desired action name, and you are setting it to CatalogMenu, but then you're then creating an object that says "Index". For this reason (as I have no idea what you want 'CatalogMenu' to be), I have taken it out.

Please also note the null after the routeValues object. This is because the 10 constructors for Html.ActionLink, this one fits the best:

ActionLink(LinkText, ActionName, ControllerName, RouteValues, HtmlAttributes)

Also, if you use <% ... %> instead of <%= ... %>, then it will not output the link. This is because the ActionLink returns a string. All the '=' does in the tag is effectively a Response.Write.

Hope this explains it.

Dan Atkinson
Html.RouteLink(string linkText, string routeName, object routeValues) - Does that help clear it up more?
Lol. RouteLink. I didn't see that! I thought you were using ActionLink. :)
Dan Atkinson
Could you please update the question with your routes? In particular, CatalogMenu?
Dan Atkinson