【问题标题】:How to bind Syncfusion MVC grid to a specific list property in my model如何将 Syncfusion MVC 网格绑定到我的模型中的特定列表属性
【发布时间】:2018-04-10 17:48:42
【问题描述】:

我可以将我的网格绑定到整个模型,这是一个工作网格的示例:

(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&lt;API_EventListDTO&gt;

但是现在我需要将新网格绑定到模型的特定属性,该属性是项目列表。我怎样才能做到这一点?我需要在@(Html.EJ().Grid&lt;API_EventListDTO&gt;("EventListGrid").Datasource(Model) 中写什么??

谢谢

【问题讨论】:

    标签: asp.net-mvc syncfusion


    【解决方案1】:

    我怀疑您需要使用 Model 将列表绑定为网格的数据源。请参考以下示例和代码示例。

    示例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 的列表对象存储在一个新的类对象中,并将其作为模型传递。通过这种方式,可以在视图页面中使用模型参数访问所需的列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-25
      • 1970-01-01
      • 2020-03-15
      • 2012-04-02
      • 2013-05-01
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多