【发布时间】:2012-07-03 07:37:23
【问题描述】:
你好;各种解决方案绑定数据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)' 有一些无效参数
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-3 model-view-controller