将所选值 Id 从父级传递给子级 Kendo DropdownList
pass selected value Id from parent to child Kendo DropdownList
我有一个使用 jquery 和 Kendo UI 的级联 Kendo DropdownList。我的问题是我想将选定的值 Id 从父级传递给子级,这意味着将 StateId 传递给城市 DropdownList 并根据选定的 StateId 过滤城市但是当我尝试调试它时我遇到了一些奇怪的事情,即 StateId 为空。有没有人可以帮助我?谢谢。
[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);
}
如您所见,该值为空,这是我的 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...",
delay: 10,
dataTextField: "Name",
dataValueField: "CityId",
autoBind: false,
dataSource: {
type: "json",
serverFiltering: true,
transport: {
read: {
headers: {
"__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val()
},
type: "Post",
dataType: "json",
url: "/Supervision/Tracking/GetCities"
}
},
schema: { data: 'Data' }
}
}).data("kendoDropDownList");
when I tried to debug it I faced something weird which was that the StateId is null.
我使用 Kendo UI jQuery DropDownList 和 ASP.NET 核心 WebAPI 作为后端服务进行了测试,我可以重现同样的问题。
根据JS客户端发出的请求的formdata,ASP.NET核心端点可以很好地接受和处理这些数据,您可以尝试以下解决方法。
自定义模型类
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
测试结果
我有一个使用 jquery 和 Kendo UI 的级联 Kendo DropdownList。我的问题是我想将选定的值 Id 从父级传递给子级,这意味着将 StateId 传递给城市 DropdownList 并根据选定的 StateId 过滤城市但是当我尝试调试它时我遇到了一些奇怪的事情,即 StateId 为空。有没有人可以帮助我?谢谢。
[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);
}
如您所见,该值为空,这是我的 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...",
delay: 10,
dataTextField: "Name",
dataValueField: "CityId",
autoBind: false,
dataSource: {
type: "json",
serverFiltering: true,
transport: {
read: {
headers: {
"__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val()
},
type: "Post",
dataType: "json",
url: "/Supervision/Tracking/GetCities"
}
},
schema: { data: 'Data' }
}
}).data("kendoDropDownList");
when I tried to debug it I faced something weird which was that the StateId is null.
我使用 Kendo UI jQuery DropDownList 和 ASP.NET 核心 WebAPI 作为后端服务进行了测试,我可以重现同样的问题。
根据JS客户端发出的请求的formdata,ASP.NET核心端点可以很好地接受和处理这些数据,您可以尝试以下解决方法。
自定义模型类
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
测试结果