如何将webgrid视图更改为列表视图

时间:2015-02-27 10:03:23

标签: asp.net asp.net-mvc-4

我想在列表视图中显示静态数据。我已经通过在mvc4中使用webgrid来提取数据并显示在网格视图中。

我想在列表视图中显示数据,有人可以告诉我如何在列表视图中显示数据。

这是我在视图中的代码

<div id="gridContent" class="list">
    @grid.GetHtml(tableStyle: "webGrid",
            headerStyle: "header",
            alternatingRowStyle: "alt",
            selectedRowStyle: "select",
            columns: grid.Columns(
            grid.Column("FName","FName"),
            grid.Column("LName", " LName"),
            grid.Column("Age","Age"),
            grid.Column("Email","Email"),
            grid.Column("Contact","Contact")
            )
            )
</div>

用于向webgrid显示数据的静态数据     控制器:

 public ActionResult WebGridSample()
 {
    List<EmployeeDetails> emp = new List<EmployeeDetails>();
    emp.Add(new EmployeeDetails { FName = "John", LName = "Adam", Age = "21", Email = "john@123.@gmail.com", Contact = "978546320" });
    return View("WebGridSample",emp);
 }

模特:

  public class EmployeeDetails
    {
        public string FName { get; set; }
        public string LName { get; set; }
        public string Age { get; set; }
        public string Email { get; set; }
        public string Contact { get; set; }
    }

注意:列出视图,例如电子商务网站中的搜索结果。

Fname 
___________________________________________
LName
___________________________________________
Age
____________________________________________

http://www.vandelaydesign.com/list-grid-view-switch/

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码在列表中显示您的数据:

//if not already done set the model for your page
@model IEnumerable<EmployeeDetails>
//........
<ul>
    @foreach (EmployeeDetails ED in Model)
    {

    <li>
      <section>@ED.FName</section>
      <section>@ED.LName</section>
      <section>@ED.Age</section>
    </li>
    }
</ul>