如何动态绑定Kendo MVC UI下拉列表 [英] How to bind kendo mvc ui dropdownlist dynamically

查看:108
本文介绍了如何动态绑定Kendo MVC UI下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Kendo UI mvc开发asp.net mvc.我有两个剑道下拉列表.一个用于诊所列表,另一个用于所选诊所中的患者列表.但是,使用级联下拉列表时,诊所和患者之间没有直接关系.为此,我在下拉列表更改事件中使用了ajax调用,并获取了患者列表.这是我第一个列出诊所的下拉列表

I am working on asp.net mvc with Kendo UI mvc. I have two kendo dropdown lists. one for list of clinics and another of list of patients in selected clinic. But there is no direct relationship between clinic and patient to use the cascading dropdownlist. for that i have used ajax calls in dropdownlist change event and get list of patients. and this is my first dropdownlist for list clinics

 @(
  Html.Kendo().DropDownList()
  .Name("ddlClinics")
  .Events(e=>e.Change("ChangeClinic"))
  .BindTo(new SelectList((List<Account.Entities.Clinic>)ViewBag.lstClinic,
 "ClinicID", "ClinicName")))

这是我的第二个针对名单患者的下拉列表

and this is my second dropdownlist for listpatients

@(
 Html.Kendo().DropDownList()
.Name("ddlPatients")
.BindTo(new SelectList((List<Patient>)ViewBag.Patients, 
"PatId", "PatName"))))

我想在第一个下拉列表更改时将患者列表动态绑定到第二个下拉列表,

I want to dynamically bind the list of patients to second dropdownlist when the first dropdownlist changes,

function ChangeClinic()
{
$.ajax({
url: '/Messages/GetPatient',
 type: 'Post',
 data: { email: '@User.Identity.Name' },
 cache: false,
 success: function (result) {
 var ddlPatients = $('#ddlPatients').data('kendoDropDownList');
 var main = [];
 $.each(result, function (k, v) {
 main.push({ "PatId": v.PatId, "PatName": v.PatName });
  });
  ddlPatients.dataTextField = "PatName";
  ddlPatients.dataValueField = "PatId";
  ddlPatients.dataSource.data(main);
  ddlPatients.reload();
 }
 });
}

我可以将列表绑定到下拉列表,但是所有项目均显示为未定义" .所以请引导我.

i am able to bind the list to dropdownlist but all items are shows as 'undefined'. so please guide me.

推荐答案

据我所知,诊所和患者之间存在联系,因此您应该能够使用 .对于学区与学校之间的关系,我们以类似的方式使用级联下拉列表:

From what I can tell, there is a relationship between clinics and patients so you should be able to use the CascadeFrom("DropDownList1") provided in the wrappers. We use a cascading dropdownlist in a similar fashion for the relationship between school districts and schools:

@(Html.Kendo().DropDownList()
            .Name("District")
            .HtmlAttributes(new { style = "width:300px;" })
            .BindTo(ViewBag.districts)
            .DataTextField("DistrictName")
            .DataValueField("DistrictID")
            .OptionLabel("Select District")
)
@(Html.Kendo().DropDownList()
            .Name("School")
            .HtmlAttributes(new { style = "width:300px;" })
            .CascadeFrom("District")
            .BindTo(ViewBag.schools)
            .DataTextField("SchoolName")
            .DataValueField("SchoolID")
            .OptionLabel("Select School")
)

这篇关于如何动态绑定Kendo MVC UI下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆