Asp.net mvc 4 如何在MVC4.0(Razor)中以表格格式显示产品
目前,我的数据以如下方式显示在行中 项目1项目2项目3项目4项目5 我使用以下代码得到这个结果Asp.net mvc 4 如何在MVC4.0(Razor)中以表格格式显示产品,asp.net-mvc-4,Asp.net Mvc 4,目前,我的数据以如下方式显示在行中 项目1项目2项目3项目4项目5 我使用以下代码得到这个结果 @using SportsStore.Models.WebUI @model SportsStore.Models.ProductsListViewModel @{ ViewBag.Title = "Products"; } <div style="padding-left: 300px;"> <table style="height: 300px; border:
@using SportsStore.Models.WebUI
@model SportsStore.Models.ProductsListViewModel
@{
ViewBag.Title = "Products";
}
<div style="padding-left: 300px;">
<table style="height: 300px; border: 2px; border: 1px solid Red;">
<tr>
@foreach (var p in Model.Products)
{
<td style="height: 100px; width: 150px; border: 2px">
<a href="@Url.Action("Detail", "Product",
new { id = p.ProductID })">
<img alt="@p.ProductDescription" src="@p.Imagename" width="150" height="150"/>
<br />
Name : @p.ProductDescription<br />
Price : <span>@p.RetailPrice</span> </a>
</td>
}
</tr>
</table
</div>
@使用sportstore.Models.WebUI
@model SportsStore.Models.ProductsListViewModel
@{
ViewBag.Title=“产品”;
}
@foreach(模型产品中的var p)
{
}
你可以使用div。首先为outher div设置width
size,然后设置width
size单元格divs和float:left
,如下所示
<div style="padding-left: 300px;width:750px;">
@foreach (var p in Model.Products)
{
<div style="height: 100px; width: 150px; float:left;">
<a href="@Url.Action("Detail", "Product",
new { id = p.ProductID })">
<img alt="@p.ProductDescription" src="@p.Imagename" width="150" height="150"/>
<br />
Name : @p.ProductDescription<br />
Price : <span>@p.RetailPrice</span> </a>
</div>
}
</div>
@foreach(模型产品中的var p)
{
}
因此,如果您的outher divwidth=750
和cell divswidth=150
则有750/150=5列。因此,它可以自动在每行中创建5列。您可以使用div。首先为outher div设置width
size,然后设置width
size单元格divs和float:left
,如下所示
<div style="padding-left: 300px;width:750px;">
@foreach (var p in Model.Products)
{
<div style="height: 100px; width: 150px; float:left;">
<a href="@Url.Action("Detail", "Product",
new { id = p.ProductID })">
<img alt="@p.ProductDescription" src="@p.Imagename" width="150" height="150"/>
<br />
Name : @p.ProductDescription<br />
Price : <span>@p.RetailPrice</span> </a>
</div>
}
</div>
@foreach(模型产品中的var p)
{
}
因此,如果您的outher divwidth=750
和cell divswidth=150
则有750/150=5列。因此,它可以自动在每行中创建5列。在divs not table中显示它。您好,您可以为我提供更多信息吗?在divs not table中显示它。您好,您可以为我提供更多信息吗?非常感谢您的帮助。非常感谢您的帮助。