Using the MVC model to populate and validate a multi-element kendo?

I am trying to link my kendo multielement to the property in the model using mvc 5, but all I get is a list of undefined elements. The list is correct at the controller level and, looking at the source code, the list is correct there, but I can not visualize the list.

What is also perplexing is that there are more undefined elements in the list, and then elements of the actual list in the model.

Can someone explain what is happening or show me how to debug and fix the problems that I am having.

Model:

[Required] public SelectList hierarchy { get; set; } public virtual IEnumerable<SelectListItem> Hierarchy { get { var hierarchies = new List<Company>(); hierarchies = RoleCompanyHelper.GetHierachies(); var hierarchiesList = new List<SelectListItem>(); foreach (var hierarchy in hierarchies) { hierarchiesList.Add(new SelectListItem { Value = hierarchy.CompanyID.ToString(), Text = hierarchy.CompanyName }); } return new SelectList(hierarchiesList, "Value", "Text"); } } 

Controller:

 public ActionResult Index() { var vm = new AXCurrentRolesViewModel(); return View(vm); } 

View:

 @model TelerikMvcApp1.Models.AXCurrentRolesViewModel @(Html.Kendo().MultiSelect() .Name("addRoleCompany_hierarchy") .BindTo(new SelectList("Value", "Text")) .Value(Model.hierarchy) .DataTextField("HierarchyName") .DataValueField("HierarchyID") .Placeholder("Select Hierarchy...") .Filter(FilterType.StartsWith) .AutoBind(false) ) 

A little separate note, why does my standard model check always return true ??

Thanks for any help and advice on these issues.

EDIT Source Code

 <select id="addRoleCompany_hierarchy" multiple="multiple" name="addRoleCompany_hierarchy"></select> <script> jQuery(function(){jQuery("#addRoleCompany_hierarchy").kendoMultiSelect({"dataSource":[{"Text":"All Companies Inc IFRS \u0026 Consol","Value":"55"}, {"Text":"All Posting Companies (exc POC \u0026 Investments)","Value":"56"}, {"Text":"BUUK Group Structure","Value":"57"}, {"Text":"Cardiff Entities","Value":"58"}, {"Text":"Department","Value":"59"}, {"Text":"GTC/GPL/ENC/IPL/QPL/EAM","Value":"60"}, {"Text":"GTC/GUC/CUL","Value":"61"}, {"Text":"GTCConsoleAndOperationalCompanies","Value":"62"}, {"Text":"GTCOperationalCompanies","Value":"63"}, {"Text":"Inexus Companies","Value":"64"}, {"Text":"Investment Companies Only","Value":"65"}, {"Text":"PIL/POL","Value":"66"}],"dataTextField":"HierarchyName","filter":"startswith","autoBind":fal se, "dataValueField":"HierarchyID","placeholder":"Select Hierarchy..."});}); </script> 
+6
source share
1 answer

Change

 .DataTextField("HierarchyName") .DataValueField("HierarchyID") .DataTextField("Text") .DataValueField("Value") 
+2
source

Source: https://habr.com/ru/post/979635/


All Articles