【发布时间】:2014-09-16 19:02:38
【问题描述】:
我是 ASP.NET MVC 的新手。
我在 Web 表单中创建了一个包含 DataList 控件的页面。以下是标记
<asp:DataList ID="dtlProducts" ShowFooter="true" runat="server" RepeatDirection="Horizontal" RepeatColumns="4"
BorderStyle="None">
<FooterStyle ForeColor="Red" HorizontalAlign="Center" Font-Bold="True" />
<ItemTemplate>
<table class="list">
<tbody>
<tr>
<td style="width: 25%;">
<a href='<%#Eval("ProductId","ProductDetails.aspx?ProductId={0}") %>'>
<img width="120px" height="120px" src='<%#Eval("productImage", "admin/Uploads/Product/{0}") %>' alt='<%#Eval("ProductName") %>' />
</a>
<br />
<a href='<%#Eval("ProductId","ProductDetails.aspx?ProductId={0}") %>'>
<%#Eval("ProductName") %>
</a>
<br />
<span style="color: rgb(153, 153, 153); font-size: 11px;">
<%#Eval("productDescription")%>
</span>
<br />
<span style="color: rgb(153, 0, 0); font-weight: bold;"><span style="font-family: Rupee Foradian">`</span>
<%#Eval("productPrice")%>
</span>
<br />
</td>
</tr>
</tbody>
</table>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblEmpty" Text="Coming Soon" runat="server" Visible='<%#bool.Parse((dtlProducts.Items.Count==0).ToString())%>'>
</asp:Label>
</FooterTemplate>
</asp:DataList>
此标记生成以下结构
现在,我正在尝试使用 ASP.NET MVC 4 来实现同样的目标
这是我在剃须刀中尝试过的:
<table style="border-style:none;border-collapse:collapse;" id="tblProducts">
<tr>
@foreach (var item in ViewBag.Product)
{
<td>
<table class="list">
<tbody>
<tr>
<td style="width: 25%;">
<a href="ClientHome/Index/@item.ProductId">
<img width="120px" height="120px" alt="@item.ProductName" src="../Uploads/Product/@item.Image">
</a>
<br>
<a href="ClientHome/Index/@item.ProductId">
@item.ProductName
</a>
<br>
<span style="color: rgb(153, 153, 153); font-size: 11px;">
@item.Description
</span>
<br>
<span style="color: rgb(153, 0, 0); font-weight: bold;">
<span style="font-family: Rupee Foradian">`</span>
@item.Price
</span>
<br>
</td>
</tr>
</tbody>
</table>
</td>
}
</tr>
</table>
这会生成以下结构
我的剃须刀到底应该换什么?
【问题讨论】:
-
它必须是表格布局还是您可以使用响应式网格布局?
-
这是一个样式问题,而不是剃须刀。由于它不是真正的表格数据,请考虑在样式为
float:left和width:25%的 div 中呈现内容 -
@Serv 是什么意思?
-
这意味着你有一个固定的布局,不能很好地适应屏幕尺寸。响应式布局适应屏幕尺寸。例如:如果宽度因为在智能手机上查看而变小,则根据可用的视图空间,列从 4 下降到 3 到 2 到单列。
-
+1 @StephenMuecke 这确实有点帮助。
标签: c# html asp.net-mvc-4 razor