-1

我是 mvc 的新手。我正在使用 mvc 项目。这是一个购物车项目。在 asp.net web 表单中,我们使用了数据列表控件,并且我们还设置了一个 RepeatColumns 属性,例如 5、10、20。MVC 中的替代方法是什么?我也可以在 MVC 中使用相同的控件吗?

那么谁能告诉我如何在数据列表控件中显示我的数据?

4

2 回答 2

1

要在一行中有五个产品图像,您可以使用两个循环并以剃刀语法执行此操作....

<div>
<table>
@for(int i = 0; i <= (Model.Count - 1) / 5; ++i)  /*Five is no of product record count per row*/
{
 <tr>
 for(int j = 0; j < 5 && i + j < Model.Count; ++j) {
  <td style="width:240px;margin-left:30px; margin-right:30px;"> /*Adjust based on your HTML and CSS requeirment*/
   <img src="@Product.ImageSource" alt="drawing" />
   <Div>@Product.Title</Div>     
  </td>
 }
 </tr>
}
</table>
</div>

以上可用于每行生成 5 个产品图像....

于 2012-10-01T07:10:24.617 回答
0

well theoretically there are no server controls available in asp.net MVC.. For learning you can check what are the other differences in asp.net web form and MVC peradigm and must read this link. So you get overview what you can do and can't in MVC.

Now to display repeatable data in MVC you need to use LOOP and presant usign HTML helpers. You can adopt RAZOR syntax or Asp.net Syntax to show the data.

E.g in Razor you can have something like following to mimic the Repeater requirements.

<div class="container">
    <header>
        <h3>Auctions</h3>
    </header>

    <ul id="auctions">

    @foreach(var auction in Model.Auctions) {
        <li>
            <h4 class="title">
                <a href="@auction.Url">@auction.Title</a>
            </h4>
        </li>
    }

    </ul>
</div>

TO quickly learn what is MVC and how to do Bookbinding you can refer Music Store tutorial by Microsoft that explains basic necessarily things for MVC learner.

You question is little off topic but I love to answer them. ;) Happy coding

于 2012-09-25T10:04:16.867 回答