将其他数据发布为列表kendo multiselect读取 [英] Post additional data as list kendo multiselect read
问题描述
我有两个剑道多重选择,我希望我的角色多重选择能够与其他角色进行级联,以便在读取多重选择角色时,我想发布系统多重选择中所选值的列表.这是我的多选角色的样子:
I have a two kendo multiselect and i want my roles multiselect to sort of cascade from the other in a way that on the roles multiselect read i want to post a list of the values selected in my systems multiselect. This is what my roles multiselect looks like:
@(Html.Kendo().MultiSelect()
.Name("Roles")
.DataTextField("Name")
.DataValueField("Id")
.Placeholder("Select roles")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetRoles", "UserAdmin").Data("additionalItemsGetRoles");
})
.ServerFiltering(true);
})
)
<script>
function additionalItemsGetRoles() {
var multiselect = $("#Systems").data("kendoMultiSelect").dataItems();
var length = multiselect.length;
var systems = [];
for (var i = 0; i < length; i++) {
systems.push({
Name: multiselect[i].Name,
SystemId: multiselect[i].SystemId,
Description: multiselect[i].Description
});
}
var json = JSON.stringify(systems);
console.log(json);
return json;
}
</script>
这是我的操作方法:
public ActionResult GetRoles([DataSourceRequest] DataSourceRequest request, IList<SystemViewModel> systems)
{
这是我的console.log(json)在控制台中显示的内容.
And here is what my console.log(json) shows in the console.
这是我的视图模型:
public string SystemId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
我试图将操作方法设置为[httpPost],但是根本找不到该方法.
I tried to set the action method as [httpPost] but then it can't find the method at all.
每次将其发布到控制器时,它都会为null.我在这里做错什么了?
Everytime it posts to the controller it get null. What am i doing wrong here?
推荐答案
好的,如果我理解正确的话,您想要做的就是根据另一个多重选择列表中的选定项过滤一个多重选择列表.是吗?
OK, if I understand correctly, what you want to do is to filter one multiselect list, based on the selected items in another multiselect list. Yes?
我实际上正在做类似的事情,这是我所做的:
I am actually doing something similar, and here is what I did:
首先,设置两个MultiSelect小部件" 在第一个MultiSelect上设置Change事件("regionChange") 将DataSource的.Data参数设置为js函数("regionfilter")
First, setup the two MultiSelect "widgets" Set the Change event on the first MultiSelect ("regionChange") Set the .Data parameter of DataSource to a js function ("regionfilter")
@(Html.Kendo().MultiSelect()
.Name("region")
.DataTextField("Name")
.DataValueField("Id")
.AutoBind(false)
.Events(e => e.Change("regionChange"))
.DataSource(ds => ds
.Read(read => read.Action("GetRegionsForFilter", "Authorization")
)
)
@(Html.Kendo().MultiSelect()
.Name("branch")
.DataTextField("Name")
.DataValueField("Id")
.AutoBind(false)
.DataSource(ds => ds
.Read(read => read.Action("GetBranchesForFilter", "Authorization")
.Data("regionfilter"))
.ServerFiltering(true)
)
)
定义js函数(我还有一个额外的函数来获取MultiSelect值,因为我在没有页面的其他两个MultiSelect"widgets"上使用了此函数,而且我实际上是对某些对象(例如Branch/区域,但我截断了对区域进行的过滤)
Define js functions (I have an additional function to get the MultiSelect values, because I am using this on a couple of other MultiSelect "widgets" no the page, AND I am actually doing reverse filtering for some (such as Branch/Region though I snipped out the filtering being done on region)
function regionChange() {
var value = this.value(),
grid = $("#grid").data("kendoGrid");
<-- snipped logic related to filtering grid -->
$('#branch').data('kendoMultiSelect').dataSource.read();
}
function regionfilter() {
var values = getMultiSelectValues("region");
return { regions: values.toString() };
}
function getMultiSelectValues(multiSelectControl) {
var multiSelect = $("#" + multiSelectControl).data("kendoMultiSelect");
var values = multiSelect.value($("#value").val());
return values;
}
最后,在我的控制器中,我只是返回一个JsonResult(获取请求),它接受一个字符串参数(用逗号分隔的字符串列表)
Finally, in my controller I am just returning a JsonResult (get request) that accepts a string argument (comma separated list of strings)
public JsonResult GetBranchesForFilter(string regions)
{
var list = _repository.Branches().GetAll().Select(x => new { x.Id, x.Name, x.RegionId });
if (!String.IsNullOrWhiteSpace(regions))
list = list.Where(x => regions.Contains(x.RegionId.ToString()));
return Json(list.OrderBy(o => o.Name), JsonRequestBehavior.AllowGet);
}
这篇关于将其他数据发布为列表kendo multiselect读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!