隐藏

MVC 如何在页面获取list集合

发布:2014/11/10 13:24:12作者:管理员 来源:本站 浏览次数:1425

第一种 list
 <% List<AccountBook.Models.Payment> payments = ViewData["Payments"] as List<AccountBook.Models.Payment>; %>
        <table>
            <tr>
                <th>
                    消费日期
                </th>
                <th>
                    消费数目
                </th>
                <th>
                    内容
                </th>
                <th>
                    备注
                </th>
            </tr>
            <% foreach (var pay in payments)
               { %>
            <tr>
                <td>
                    <%= Html.Encode(pay.PaymentDate)%>
                </td>
                <td>
                    <%= Html.Encode(pay.PaymentMoney)%>
                </td>
                <td>
                    <%= Html.Encode(pay.PaymentContent)%>
                </td>
                <td>
                    <%= Html.Encode(pay.Remark)%>
                </td>
            </tr>
            <% } %>
        </table>

第二种    

<%= Html.DropDownList("dplProvince", ViewData["ProvinceList"] as List<SelectListItem>)%></center>
第三种


IList lists=SelectAll();
lists= ViewData["LIST"] ;

//界面上取值
 <% for(int i=0;i< ViewData["LIST"].count;i++ ){%>

<%}%>

第四种


public ActionResult Index()
            { 
                List<UserModel> list = new List<UserModel>();
                list.Add(new UserModel { Age = 10, Password = "123", UerName = "小一" });
                list.Add(new UserModel { Age = 20, Password = "456", UerName = "小二" });
                list.Add(new UserModel { Age = 30, Password = "789", UerName = "小三" });
                return View(list);
            }

public class UserModel
{
public Age{get;set;}
public Password{get;set;}
public UerName{get;set;}
}

Index.cshtml
@Model UserModel

第五种

<%FuFangAdmin.Controllers.PhoneController p = new FuFangAdmin.Controllers.PhoneController();%>

<select id="NetworkType" name="NetworkType">
            <% foreach (var dic in p.NetType)
               { %>
               <option value="<%= Html.Encode(dic.Code)%>"><%= Html.Encode(dic.Text)%></option>
               <%} %>
            </select>