asp .net MVC3中的DataList [英] DataList in asp .net MVC3
本文介绍了asp .net MVC3中的DataList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在mvc3中创建数据列表。我无法做到。请帮助我
这是我的代码在asp
How can i make the data list in mvc3 .I cant do it .pls help me
this is my code in asp
<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>
推荐答案
ASP.NET MVC没有服务器控件。你可以在你的模型上使用一个简单的foreach循环(你也可以使用局部视图)。
您也可以创建HTML帮助器作为替代http://www.asp.net/mvc/tutorials/older-versions/views / creating-custom-html-helpers-cs [ ^ ]
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[^]
请像这样放置。为此,您可以制作自己的自定义html助手。
Please put like this. For this you can make your own Custom html helper.
@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>
}
以下是两个有用的链接
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 [ ^ ]
希望这有帮助
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
这篇关于asp .net MVC3中的DataList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文