剑道UI DetailTemplate网格数据源读取不火的动作在控制器

本文关键字:控制器 DetailTemplate UI 网格 数据源 读取 剑道 | 更新日期: 2023-09-27 18:02:25

我使用分层网格,我绑定父网格,但分层网格在加载时没有绑定,它显示空也没有控制器动作方法与分层网格数据源读取方法相关联。我的观点是

   @(Html.Kendo().Grid<Cubes.UI.Models.PatientAppointmentInfoModel>()
     .Name("PatientAppointmentGrid")
     .DataSource(dataSource => dataSource
          .Ajax()                                                   
          .PageSize(Cubes.Common.Constants.GridPageSize)
          .Read(read => read.Action("_SearchPatientAppointment", "PatientAppointment"))
     )
     .Columns(columns =>
     {
         columns.Bound(m => m.AppointmentID).Title("Appointment #");
         columns.Bound(m => m.StartTime).Title("Start Time").Width(100);
         columns.Bound(m => m.EndTime).Title("End Time");
         columns.Bound(m => m.AppointmentDate).Format("{0:d}").Title("Appointment Date");
         columns.Bound(m => m.FirstName).Title("First Name");
         columns.Bound(m => m.LastName).Title("Last Name");
         columns.Bound(m => m.Amount).Title("Amount");
     })
     .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
     .Pageable()
     .Sortable()
     .Scrollable()
     .ClientDetailTemplateId("template")
     .Resizable(resize => resize.Columns(true))
     .Events(events =>              
         events.DataBound("OnDataBoundPatientAppointmentGrid"))
     )

和详细模板如下

<script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<Cubes.UI.Models.PatientAppointmentInfoModel>()
        .Name("Grid_#=AppointmentID#")
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(Cubes.Common.Constants.GridPageSize)
            .Read(read => read.Action("HierarchyBinding_Appointments", "PatientAppointment", new { appointmentID = "#=AppointmentID#" }))
         )
         .Columns(columns =>
         {
             columns.Bound(t => t.AppointmentID).Title("Appoitnet_#=AppointmentID#");
             columns.Bound(t => t.StartTime).Width(100);
             columns.Bound(t => t.EndTime);
             columns.Bound(t => t.AppointmentDate).Format("{0:d}").Title("Appointment Date");
             columns.Bound(t => t.FirstName);
             columns.Bound(t => t.LastName);
             columns.Bound(t => t.Amount);
          })
          .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
          .Pageable()
          .Sortable()
          .Resizable(resize => resize.Columns(true))
          .ToClientTemplate()
    )
</script>

控制器中的动作方法如下

 public ActionResult HierarchyBinding_Appointments( [DataSourceRequest]DataSourceRequest request,string appointmentID, string searchKey, string columnNameToSort, string defaultSortOrder, string Mobile, PatientAppointmentInfoModel model)
    {
        //model.Mobile = Mobile;
        var filter = BuildSearchDescriptor(model);
        if (filter != null)
        {
            IList<IFilterDescriptor> filters = new List<IFilterDescriptor>();
            filters.Add(filter);
            request.Filters = filters;
        }
        var roles = GetPatientAppointmentsForChild(Convert.ToInt32(appointmentID),request);
        var result = new DataSourceResult
        {
            Data = roles.Results,
            Total = roles.RowCount

        };
        return Json(result, JsonRequestBehavior.AllowGet);
    }

剑道UI DetailTemplate网格数据源读取不火的动作在控制器

问题

Detail Grid只传递了new { appointmentID = "#=AppointmentID#" },但是动作方法HierarchyBinding_Appointments有太多的参数——appointment、searchKey等。

解决方案

你需要通过对象路由值或JavaScript函数传递额外的数据。

下面是JavaScript函数的示例。

.Read(read => read
   .Action("HierarchyBinding_Appointments",  "PatientAppointment")
   .Data("patientAppointmentData(#=AppointmentID#"))
<script type="text/javascript">
   function patientAppointmentData(AppointmentID) {
      return {
         appointmentID: AppointmentID, 
         searchKey: xxx, 
         columnNameToSort: xxx, 
         defaultSortOrder: xxx, 
         Mobile: xxx 
      };
   }
</script>

动作方法
public ActionResult HierarchyBinding_Appointments( 
   [DataSourceRequest]DataSourceRequest request, 
   MyModel model)
{
}

视图模型
public class MyModel 
{
   public xxx AppointmentID { get; set; } 
   public xxx SearchKey { get; set; } 
   public xxx ColumnNameToSort { get; set; } 
   public xxx DefaultSortOrder { get; set; } 
   public xxx Mobile { get; set; } 
}