我是新來的asp.net mvc 3.我正嘗試使用mvc3生成動態gridview,但是我無法生成網格。我下面的代碼:如何使用mvc 3 aspx引擎創建動態網格?
型號:
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"))
動態返回控制器動作。如何返回動態列或動態gridview或擴展?
你能更清晰,動態列?你究竟是什麼意思的動態列? –
你的意思是你想讓每一列讀取一個動態值?或者從字面上將「FirstName」作爲第1列,將「LastName」作爲第2列,將「Salary」作爲第3列? – Ecnalyr
[ASP.NET MVC $ .post調用返回字符串的可能的重複...需要與格式爲jqGrid幫助](http://stackoverflow.com/questions/4101116/asp-net-mvc-post-call-returning- string-need-help-with-format-for-jqgrid) – programmerist