我可以将网格绑定到整个模型,这是一个工作网格的示例:
(Html.EJ().Grid<API_EventListDTO>("EventListGrid")
.Datasource(Model)
.Columns(col =>
{
col.Field("EventId").HeaderText("Event ID").TextAlign(TextAlign.Center).Width(75).Add();
col.Field("EventTypeDescription").HeaderText("Event Description").TextAlign(TextAlign.Center).Width(75).Add();
col.Field("CreatedOn").HeaderText("Created On").TextAlign(TextAlign.Center).Width(75).Add();
col.Field("Status").HeaderText("Status").TextAlign(TextAlign.Center).Width(75).Add();
col.Field("Message").HeaderText("Message").TextAlign(TextAlign.Center).Width(75).Add();
}))
在这种情况下,模型是@model List<API_EventListDTO>
。
但是现在我需要将新网格绑定到模型的特定属性,该属性是项列表。我怎样才能做到这一点?我需要在@(Html.EJ().Grid<API_EventListDTO>("EventListGrid")
和.Datasource(Model)
??
谢谢
答案 0 :(得分:0)
我怀疑您需要使用Model将列表绑定为网格的dataSource。请参考以下示例和代码示例。
示例here
@model EJGrid.Controllers.HomeController.newclass
@(Html.EJ().Grid<Orders>("FlatGrid")
.Datasource(Model.empID)
.AllowPaging()
…..
)
[Controller.cs]
public class HomeController : Controller
{
public static List<Orders> order = new List<Orders>();
public static List<EmpID> emp = new List<EmpID>();
public ActionResult Index()
{
List<EmpID> emp1 = new List<EmpID>() { new EmpID() { ID = 1, Name = "Ewddada" }};
List<EmpID> emp2 = new List<EmpID>() { new EmpID() { ID = 2, Name = "Caxada" }};
List<EmpID> emp3 = new List<EmpID>() { new EmpID() { ID = 3, Name = "Nmbddj" }};
List<EmpID> emp4 = new List<EmpID>() { new EmpID() { ID = 4, Name = "Mbgfuydf" }};
List<EmpID> emp5 = new List<EmpID>() { new EmpID() { ID = 5, Name = "Nuhjbsd" }};
order.Add(new Orders( 1, "VINET", emp1, 32.38, new DateTime(2014, 12, 25), "Reims"));
order.Add(new Orders( 2, "TOMSP", emp2, 11.61, new DateTime(2014, 12, 21), "Munster"));
order.Add(new Orders( 3, "ANATER",emp3, 45.34, new DateTime(2014, 10, 18), "Berlin"));
order.Add(new Orders( 4, "ALFKI", emp4, 37.28, new DateTime(2014, 11, 23), "Mexico"));
order.Add(new Orders( 5, "FRGYE", emp5, 67.00, new DateTime(2014, 05, 05), "Colchester"));
newclass newModel = new newclass();
newModel.empID = emp1;
newModel.ord = order;
return View(newModel);
}
public class newclass {
public List<EmpID> empID { get; set; }
public List<Orders> ord { get; set; }
}
}
[Model class]
public class Orders
{
public Orders()
{
}
public Orders(int orderId, string customerId, List<EmpID> empId, double freight, DateTime orderDate, string shipCity)
{
this.OrderID = orderId;
this.CustomerID = customerId;
this.EmployeeID = empId;
this.Freight = freight;
this.OrderDate = orderDate;
this.ShipCity = shipCity;
}
public int? OrderID { get; set; }
public string CustomerID { get; set; }
public List<EmpID> EmployeeID { get; set; }
public double? Freight { get; set; }
public DateTime? OrderDate { get; set; }
public string ShipCity { get; set; }
}
public class EmpID
{
public int ID { get; set; }
public string Name { get; set; }
}
在上面的代码示例中,Orders是包含属性EMPID的模型,该属性是项列表。在控制器页面中,我们将Orders和EMPID的列表对象存储在新的类对象中,并将其作为模型传递。通过这种方式,可以使用视图页面中的Model参数访问所需列表。