Kendo UI DetailTemplate网格数据源读取控制器中的非激活操作

时间:2015-07-11 17:57:12

标签: c# asp.net-mvc-4 kendo-ui kendo-grid kendo-asp.net-mvc

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

   @(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);

    }

1 个答案:

答案 0 :(得分:0)

问题

详细信息网格只传递new { appointmentID = "#=AppointmentID#" }但操作方法HierarchyBinding_Appointments包含太多参数 - appointmentID,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; } 
}