简体   繁体   English

将 Select2 下拉列表中的参数传递给 Kendo UI MVC 数据源

[英]Pass Parameter from Select2 Dropdown to Kendo UI MVC DataSource

We just got Telerik controls today and I am trying to "switch out" the old controls for the new Kendo UI MVC Controls.我们今天刚拿到 Telerik 控件,我正在尝试为新的 Kendo UI MVC 控件“切换”旧控件。

I have a select2 multi-selection dropdownlist and I am trying to send the "selected to paramters through the Kendo UI dataSource to the controller method to return the specific records.我有一个select2多选下拉列表,我试图通过 Kendo UI 数据源将“选择到参数”发送到 controller 方法以返回特定记录。

Here is my.cshtml Razor code:这是 my.cshtml Razor 代码:

        @(Html.Kendo().Grid<ICAN.Models.Competency.ViewModels.AssessmentModel>()
                .Name("grid")
                .Columns(columns =>
                {
                    columns.Bound(c => c.AssessmentId).Width(50);
                    columns.Bound(c => c.AssessmentName).Width(350);
                    columns.Bound(c => c.NumOfUnits).Width(150);

                })
                .Sortable()
                .Pageable()
                .Scrollable()
                .ClientDetailTemplateId("unitTemplate")
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .Read(read => read.Action("GetAssessmentSearch", "Config", new { area = "Competency" }))
                )
                .Events(events=>events.DataBound("dataBound"))
            )

here is my select2 Html and jQuery:这是我的选择2 Html 和 jQuery:

<div class="form-group"><label>Assessments:</label>@Html.ListBoxFor(x => x.Assessments, new MultiSelectList(Model.assessmentSelect, "Id", "Text"), new { Id = "AssessmentId", @class = "form-control select-multiple", multiple = "multiple" })</div>

$('#AssessmentId').select2({ width: "100%", placeholder: "Select an Assessment" });

here is controller code:这是 controller 代码:

    public ActionResult GetAssessmentSearch([DataSourceRequest]DataSourceRequest request, string Assessments)
    {
        var result = service.GetAssessmentSearch(Assessments);
        return Json(result.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
    }

I have a "submit" button for the user to click after they have made multiple selections in the select2 dropdown:我有一个“提交”按钮供用户在 select2 下拉列表中进行多项选择后单击:

<button class="btn btn-alt3 mySubmit" id="submitButton" style="background-color:#bbc4cc; color:#2A4351" onclick="loadUnitTable();"> <i class="lnir lnir-checkmark-circle"></i> Submit Search Criteria</button>

In my loadAssessmentTable() which was assigned to onclick of my submit button, all that was needed was the following:在分配给我的提交按钮的onclickloadAssessmentTable()中,所需要的只是以下内容:

        var values = $('#AssessmentId').val().toString();
    grid.dataSource.read({ "Assessments": values })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM