我在我的mvc5项目中使用了Kendo MultiSelect。 所以我有一个多选的视图:
@model Library.ViewModels.Models.BookViewModel
@{
ViewBag.Title = "Edit";
}
<script>
$(document).ready(function () {
$("#multiselect").kendoMultiSelect({
placeholder: "--Select Public Houses--",
dataTextField: "PublicHouseName",
dataValueField: "PublicHouseId",
autoBind: true,
dataSource: {
transport: {
read: {
dataType: "json",
url: "/book/getallpublichouses"
}
}
}
});
$("#multiselect").getKendoMultiSelect().value([/* there must be a string array of ID's of pre-selected values here*/]);
});
</script>
我的BookViewModel看起来像这样:
public class BookViewModel
{
public int BookId { get; set; }
[Required(ErrorMessage = "This field is Required")]
[StringLength(15, ErrorMessage = "Must be under 15 characters")]
public string Name { get; set; }
public string AuthorName { get; set; }
[Required(ErrorMessage = "This field is Required")]
[Range(1, 2019, ErrorMessage = "Must be between 1 and 2019")]
public int YearOfPublishing { get; set; }
public List<int> PubHouses { get; set; }
public ICollection<PublicHouseViewModel> PublicHouses { get; set; }
}
属性public List<int> PubHouses { get; set; }
包含必须在kendo MultiSelect中预先选择的ID列表。
那么如何在kendo MultiSelect中像字符串数组中的BookViewModel.PubHouses
这样传递这个int列表呢?