Asp.Net MVC在网页中显示图像?

时间:2011-02-04 10:29:57

标签: c# asp.net-mvc

我从用户注册时存储的数据库中恢复了9个图像路径....在一个页面中,我必须在每行显示3个图像......如何做...

我用可变图像路径和用户ID ...

创建了模型类“FriendsList”
public String FriendImagePath
{
    get;
    set;
}

public int FriendUserId
{
    get;
    set;
}

我创建了视图模型类并创建了Model类的变量“FriendsList”...

public List<FriendsList> FriendsList { get; set; }

我在此处存储了9个值...

在.Aspx页面中我必须显示3行..并且在每行中我必须显示3行...

怎么做???

<tr>

<td></td>

<td></td>

<td></td>

</tr>

<tr>

<td></td>

<td></td>

<td></td>

</tr>

<tr>

<td></td>

<td></td>

<td></td>

</tr>

I have to display like this

如何做到这一点......

谢谢..

1 个答案:

答案 0 :(得分:1)

<table>
<tr>   
<% 
   int index=0;
   foreach(var friend in Model){ %>
      <% if(index%3==0){ %>
           </tr><tr>
      <% } %>   
    <td><img src="<%=Url.Content(friend.FriendImagePath) %>" /></td>
    //others prpoerties
<% 
   index++;
 } %>
</tr>
</table>