[英]How to display Image grid in MVC4
I have to show images in table format like below in MVC-4 我必须在MVC-4中以下面的表格格式显示图像
-------------------------------
| Image | image | Image |
-------------------------------
| Image | image | Image |
-------------------------------
| Image | image | Image |
-------------------------------
Paging display records 0-9 of page 1
<< < 1 2 3 > >>
For this in simple ASP.NET I am using DataList or repeater and in MVC4 I am using partial View but I am not able to show in that view like above format so can anyone help me to create partial view like above? 对于这个在简单的ASP.NET我使用DataList或转发器,在MVC4我使用局部视图但我无法在该视图中显示像上面的格式所以任何人都可以帮我创建像上面的局部视图?
Or if you have any better idea then please guide me which type of control I should use for this. 或者如果您有任何更好的想法,那么请指导我应该使用哪种控制方式。
If you have any reference link then it will also very helpful to me. 如果你有任何参考链接,那么它对我也很有帮助。
View: 视图:
@foreach
(var item in Model)
{
<tr>
<td>
@
{
string img;
if (item.AgentImage != null)
{
img = item.AgentImage.Replace("~", "..");
}
else
{
img = item.AgentImage;
}
}
<img src = '@img' height="80px" width="100px" />
</td>
</tr>
}
If your code in view looks like you wrote in comment. 如果您在视图中的代码看起来像是在评论中写的。 You need to add rows every third element.
您需要每隔三个元素添加一行。 The simplest change into your code could look like following:
对代码的最简单更改可能如下所示:
@foreach (var item in Model) {
<tr> <td>
@{
string img;
if (item.AgentImage != null)
{ img = item.AgentImage.Replace("~", ".."); }
else
{ img = item.AgentImage; }
var i=0;
if (i % 3 == 0) {
Html.Raw("</tr><tr>"); //End old row and start new one
}
i++;
}
<img src = '@img' height="80px" width="100px" />
</td></tr>
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.