如何在输入建筑物名称并单击查看按钮时显示特定值



我有使用剑道UI下拉列表和一个剑道遮面文本框和一个剑道视图按钮,我想在下拉列表中加载所有国家,并在文本框中选择特定国家对应的给定建筑名称并单击查看按钮请帮助

我正在使用mvc4剃刀在视图页面设计剑道下拉列表

我的视图页面代码是:

$(document).ready(function(){
    $("#viewbutton").click(function(){
       $.ajax({
       type:'post',
       data:{name:Buildingname},
       url:'@url.Action("GetCountry");
       success:function(data)
       {
          //response particular country name and value  also all country name
         //next what will i do 
         //how to select corresponding country name
       }
    });
});
我的控制器代码是:
public JsonResult GetCountry(string name = null)
{ 
    dataTable dt;
    if(name == null)
    {
       dt = bal.country();
       for(int i = 0; i < dt.Rows.Count; i++)
       {
           ListName.Add(new SelectListItem
           {
               Value = dt.Rows[i]["CountryId"].Tostring(),
               Text = dt.Rows[i]["CountryName"].Tostring()
           });
       }
       return Json(new SelectList(ListName, "Value", "Text"), JsonRequestBehavior.AllowGet);
   }
   else
   {
       dt = bal.country(name);
       ListName.Add(new SelectListItem
       {
          Value = dt.Rows[i]["CountryId"].Tostring(),
          Text = dt.Rows[i]["CountryName"].Tostring()
       });
       return Json(new SelectList(ListName," Value", "Text"), JsonRequestBehavior.AllowGet); 
   }
}
$.each(data,function(i,item){
 var dropdownlist = $("#mydropdownlist").data("kendoDropDownList");        
        if(item.Selected==true){
            dropdownlist.select(function(dataItem) {
              return dataItem.Text=== item.Text;
            });
        }
    });

在cs中按如下代码修改。

for(int i = 0; i < dt.Rows.Count; i++)
       {
           ListName.Add(new SelectListItem
           {
               Value = dt.Rows[i]["CountryId"].Tostring(),
               Text = dt.Rows[i]["CountryName"].Tostring()
               Selected=dt.Rows[i]["You respective field"].Tostring().Equals(name)?true:false
           });
       }
在javascript:

$.each(data,function(i,item){
    //To add item in kedo dropdown use this code
$("#mydropdownlist").data("kendoComboBox").dataSource.add({ text: item.Text, value: item.Value });
});

选择特定项目:

$.each(data,function(i,item){
 var dropdownlist = $("#mydropdownlist").data("kendoDropDownList");        
        if(item.Selected==true){
            dropdownlist.select(function(dataItem) {
              return dataItem.symbol === item.Text;
            });
        }
    });

最新更新