Click here to Skip to main content
15,888,242 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How can i make the data list in mvc3 .I cant do it .pls help me
this is my code in asp

XML
<td colspan="2">
    <asp:DataList ID="DataList1" runat="server" RepeatColumns="5" CellPadding="5" CellSpacing="5">
        <ItemStyle Width="200px" />
        <ItemTemplate>
            <table>
                <tr>
                    <td>
                        <asp:Image ID="imgProduct" runat="server" ImageUrl='<%# Eval("Path") %>' Height="150"
                            Width="150" />
                    </td>
                </tr>
                <tr>
                    <td>
                        Product Name :
                        <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Eval("ProductName") %>' />
                    </td>
                </tr>
                <tr>
                    <td>
                        Price :
                        <asp:Label ID="PriceLabel" runat="server" Text='<%# Eval("Price") %>' />
                    </td>
                </tr>
                <tr>
                    <td>
                        Description :
                        <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>' />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("Id") %>' runat="server"
                            OnClick="LinkButton1_Click">Add to Cart</asp:LinkButton>
                    </td>
                </tr>
            </table>
        </ItemTemplate>
    </asp:DataList>
</td>
Posted

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

You can create HTML helpers too as an alternative http://www.asp.net/mvc/tutorials/older-versions/views/creating-custom-html-helpers-cs[^]
 
Share this answer
 
Please put like this. For this you can make your own Custom html helper.

HTML
@foreach (var item in Model)
{ 
<span>
<table>
                <tr>
                    <td>
                        <img src="@Model.ImageSRC" />
                    </td>
                </tr>
                <tr>
                    <td>
                        @Model.ProductName
                    </td>
                </tr>
                <tr>
                    <td>
                        @Model.Price
                    </td>
                </tr>
                <tr>
                    <td>
                        @Model.Description
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.ActionLink("Add to cart")
                    </td>
                </tr>
            </table>
        </span>
}


Below are the two useful links
http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/working-with-images-in-Asp-Net-mvc-framework/[^]
http://www.devcurry.com/2012/10/aspnet-mvc-displaying-images-using.html[^]

Hope this helps
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900