开发者

asp.net mvc 3 load html table with data

net mvc 3 with the world first ever razor engine

lets say i have an array of string, well call it online users

string [] onlineusers --> it has dat开发者_JAVA百科a inside of it

now, how can i make a table using razor, and fill out it with the contents of onlineusers array? tnx

possible output
online users table (generated by mvc 3 razor | view engine)
------------
jack       |
jason      |
peter      |
juan       |
------------

also, is there a way that i can customize the html table? like make it center, upward, down, leftward. im also planning to place 3 tables loaded with different sets of data.


using the Razor syntax you could simply the data from a strongly typed model in your view

e.g.

<table>
@foreach(var onlineuser in Model.Users){
   <tr>
     <td><b>Name : </b></td>
     <td>@onlineuser</td>
   </tr>
}
<table>


Assuming your passing it in as a model

<table>
@foreach (string User in Model)
{
   <tr>
      @User
   <tr>
}
</table>

Would give you a basic table. Past that you need to use CSS to customize it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜