我是 asp.net mvc 3 的新手。我正在尝试使用 mvc3 生成动态网格视图,但我无法生成网格。我的代码如下:
模型:
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public double Salary { get; set; }
public static List<Employee> GetList()
{
List<Employee> employees = new List<Employee>{
new Employee { FirstName="Rahul", LastName="Kumar", Salary=45000},
new Employee { FirstName="Jose", LastName="Mathews", Salary=25000},
new Employee { FirstName="Ajith", LastName="Kumar", Salary=25000},
new Employee { FirstName="Scott", LastName="Allen", Salary=35000},
new Employee { FirstName="Abhishek", LastName="Nair", Salary=125000}
};
return employees;
}
}
控制器
public class EmployeeController : Controller
{
//
// GET: /Employee/
public ActionResult Index()
{
var empoyees = Employee.GetList();
return View(empoyees);
}
}
看法:
<%
var grid = new WebGrid(source: Model, defaultSort: "FirstName", rowsPerPage: 3);
using (Html.BeginForm())
{
%>
<div id="grid">
<%:grid.GetHtml(tableStyle:"grid",
headerStyle:"head",
alternatingRowStyle:"alt",
columns:grid.Columns(
grid.Column("FirstName"),
grid.Column("LastName"),
grid.Column("Salary"))) %>
</div>
<%} %>
我想创建
grid.Column("FirstName"),
grid.Column("LastName"),
grid.Column("Salary"))
动态返回控制器动作。如何返回动态列或动态网格视图或扩展?