Search code examples
asp.netasp.net-mvcdatalist

what is the equivalent of asp:datalist in asp.net-mvc


i am migrating a site over to asp.net from an asp.net site and one of the pages has a datalist as below:

 <asp:DataList ID="MyDataList" runat="server" BackColor="#EEEEEE" CellPadding="10"
    ItemStyle-HorizontalAlign="Center" GridLines="Both" Width="750" RepeatDirection="Horizontal"
    RepeatColumns="4" RepeatLayout="Table" ItemStyle-VerticalAlign="Top">
    <ItemTemplate>
        <table>
            <tr align="center">
                <td valign="top">
                    <table>
                        <tr>
                            <td width="30%">
                            </td>
                            <td>
                                <asp:HyperLink ID="HyperLink1" runat="server">
                                <asp:Image style="cursor:pointer" CssClass="instant ishadow50" ID="lnkEnlarge" runat="server"></asp:Image></asp:HyperLink>
                            </td>
                            <td width="30%">
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr align="center">
                <td>
                    <asp:Label CssClass="Comments" ID="lblComment" runat="server"></asp:Label><br>
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:DataList>

what is the equivalent in asp.net-mvc. how would i go about migrating?


Solution

  • ASP.NET MVC has no server controls. you can use a simple foreach loop on your model (you can use a partial view too).

    different option is to write a Html helper.