繁体   English   中英

如何从 Jquery 中的控制器操作读取剑道下拉列表

[英]How to read Kendo Dropdownlist from controller action in Jquery

我尝试从 Jquery 中的控制器操作中读取 Kendo Dropdownlist。 代码是

$("#CountryName").kendoDropDownList({
    dataTextField: "Description",
    dataValueField: "Id",
    dataSource: {
        transport: {
            read: {
                dataType: "jsonp",
                url: "Shared/CountryAjax"
            }
        }
    }
});

[HttpPost]
public ActionResult CountryAjax(string countryId)
{
    var countries = this._decodeBL.GetAllCountriesList();

    return new JsonResult
    {
        Data = new SelectList(countries, "Id", "Description", "Canada")
    };
}

但它从不执行 CountryAjax。 我需要这方面的帮助。 谢谢。

我从你的代码中发现了两个错误。 首先,您应该在服务器方法中使用 [HttpGet] 注释。 其次,您不应该在服务器方法中接收 countryId。

请参阅下面的固定代码。

$("#CountryName").kendoDropDownList({
    dataTextField: "Description",
    dataValueField: "Id",
    dataSource: {
        transport: {
            read: {
                dataType: "jsonp",
                url: "Shared/CountryAjax"
            }
        }
    }
});


[HttpGet]
public ActionResult CountryAjax()
{
    var countries = this._decodeBL.GetAllCountriesList();

    return new JsonResult
    {
        Data = new SelectList(countries, "Id", "Description", "Canada")
    };
}
 $("#selectYears").kendoDropDownList({
        dataTextField: "Text",
        dataValueField: "Value",
        //dataSource: data2,
        dataSource: {
            transport: {
                read: {
                    type: "GET",
                    dataType: "json",
                    url: '@Url.Action("GetYears", "NewHome")'
                }
            }
        },
        index: 0,
        change: onChange
    });

   return new JsonResult
        {
            Data = new SelectList(years, "newHomeIndexid", "selectedYear"),
            JsonRequestBehavior = JsonRequestBehavior.AllowGet
        };

暂无
暂无

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

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