你好; 各种解决方案绑定数据webgrid静态模型。但我的数据是动态的。请不要说:你为什么使用DataTable?
控制器:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(string submitButton, FormCollection fc)
{
ViewData["Customers"] = new SelectList(CustomerOperation.GetCustomers().Items, "Id", "Name", null);
ViewData["Jobs"] = new SelectList(JobOperation.GetCustomersAssemblyList().Items, "scheduleId", "name", null);
int Id = ConvertUtil.ToInt(fc["Customers"]);
int scheduleId = ConvertUtil.ToInt(fc["Jobs"]);
DataTable dt = JobOperation.GetJobsBySchedulerIdAndCustomerId(scheduleId, Id);
return View(Json(dt,JsonRequestBehavior.AllowGet));
}
看法:
<%
List<WebGridColumn> cols = new List<WebGridColumn>();
WebGrid grid = null;
if (Model != null)
{
grid = new WebGrid(source: Model.Data, rowsPerPage: 3);
System.Reflection.PropertyInfo[] propertiesofColumn = new System.Reflection.PropertyInfo[] { };
foreach (object column in Model)
{
propertiesofColumn = column.GetType().GetProperties();
}
foreach (System.Reflection.PropertyInfo propInfo in propertiesofColumn)
{
cols.Add(grid.Column(propInfo.Name, propInfo.Name));
}
}
using (Html.BeginForm())
{ %>
grid = new WebGrid(source: Model.Data , rowsPerPage: 3); .
错误:
RunTimeBinderException:最佳重载方法匹配 'System.Web.Helpers.WebGrid.WebGrid(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable, string, int, bool, bool, string, string, string, string , string, string, string)' 有一些无效参数