如何解决将所选值ID从父级传递到子级Kendo DropdownList
我有一个使用jquery和Kendo UI的级联Kendo DropdownList。我的问题是我想将父级的选定值Id传递给子级,这意味着将StateId传递给城市DropdownList并根据选定的StateId筛选城市,但是当我尝试对其进行调试时,我遇到了一件奇怪的事情,那就是StateId为null。有谁可以帮助我吗?谢谢。
[HttpPost]
public async Task<JsonResult> GetCities(DataSourceRequest request,CancellationToken cancellationToken = default)
{
request.Skip = 0;
request.Take = 2000;
var city = await _cityService.GetCities(request,cancellationToken);
return Json(city);
}
如您所见,该值为null,这是我的jquery代码的一部分...
$("#drpState").kendoDropDownList({
optionLabel: "States...",delay: 10,dataTextField: "Name",dataValueField: "StateId",dataSource: {
type: "json",serverFiltering: true,transport: {
read: {
headers: {
"__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val()
},type: "Post",dataType: "json",url: "/Supervision/Tracking/GetStates",}
},schema: { data: 'Data' }
},}).data("kendoDropDownList");
$("#drpCity").kendoDropDownList({
cascadeFrom: "drpState",optionLabel: "Cities...",dataValueField: "CityId",autoBind: false,url: "/Supervision/Tracking/GetCities"
}
},schema: { data: 'Data' }
}
}).data("kendoDropDownList");
解决方法
当我尝试调试它时,我遇到了一个奇怪的东西,那就是StateId为null。
我使用Kendo UI jQuery DropDownList和ASP.NET Core WebAPI作为后端服务进行了测试,我可以重现同样的问题。
基于JS客户端发出的请求的表单数据,要使ASP.NET Core终结点可以很好地接受和处理这些数据,您可以尝试以下解决方法。
自定义模型类
public class DataSourceRequestForCore
{
public int Take { get; set; }
public int Skip { get; set; }
public FilterForCore filter { get; set; }
}
public class FilterForCore
{
public string logic { get; set; }
public List<FilterEntry> filters { get; set; }
}
public class FilterEntry
{
[DataMember(Name = "field")]
public string Field { get; set; }
[DataMember(Name = "operator")]
public string Operator { get; set; }
[DataMember(Name = "value")]
public string Value { get; set; }
}
动作方法
[HttpPost]
public async Task<JsonResult> GetCities(DataSourceRequestForCore request,CancellationToken cancellationToken = default)
{
request.Skip = 0;
request.Take = 2000;
//....
//code logic here
测试结果
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。