MultiSelect always returns null as Editor Template

3 posts, 0 answers
  1. Mike
    Mike avatar
    10 posts
    Member since:
    Sep 2014

    Posted 13 Dec 2018 Link to this post

    I have a multiselect setup as an Editor Template utilized by the grids popup editor, the control loads properly, displays the data, allows me to select multiple Order Types, but then returns null to my model every time when I save the changes on the popup editor. 

     

    How do I wire up the value of the MultiSelect to my model when it is an Editor Template for a Grid Popup?

     

    Here is my Editor Template code:

    @model IEnumerable<int>
    @(Html.Kendo().MultiSelect()
          .Name("OrderTypeIDs")
          .DataTextField("Description")
          .DataValueField("OrderTypeID")
          .DataSource(d => d
              .Ajax()
              .Read(r => r
                  .Action("OrderTypes_Read", "Locations")
                  .Data("GetSelectedClientID")))
          .TagMode(MultiSelectTagMode.Multiple)
          .Value(Model)
          )

     

    Here is the underlying model class:

    public class LocationsModel : INotifyPropertyChanged
    {
        public LocationsModel() : base()
        {
        }
     
        [ScaffoldColumn(false)]
        public decimal LocationId { get; set; }
     
        [ScaffoldColumn(false)]
        public string ClientID { get; set; }
     
        [DisplayName("Code")]
        [Required]
        public string LocationCode { get; set; }
     
        [Required]
        public string Name { get; set; }
     
        [DisplayName("Address 1")]
        [Required]
        public string Address1 { get; set; }
     
        private string address2;
        [DisplayName("Address 2")]
        public string Address2
        {
            get => address2 ?? "";
            set => address2 = value ?? "";
        }
     
        [Required]
        public string City { get; set; }
     
        [Required]
        public string State { get; set; }
     
        [Required]
        public string Country { get; set; }
     
        [DisplayName("Zip Code")]
        [Required]
        public string ZipCode { get; set; }
     
        [DisplayName("Phone")]
        [Required]
        public string PhoneNumber { get; set; }
     
        [UIHint("OrderTypeIDs")]
        [DisplayName("Allowed Order Types")]
        public IEnumerable<int> OrderTypeIDs { get; set; }
        [DisplayName("# of O Types")]
        [ReadOnly(true)]
        public int OrderTypeCount => OrderTypeIDs?.Count() ?? 0;
     
        [ScaffoldColumn(false)]
        public string CreatedBy { get; set; }
        [ScaffoldColumn(false)]
        public DateTime CreatedOn { get; set; }
        [ScaffoldColumn(false)]
        public string LastUpdatedBy { get; set; }
        [ScaffoldColumn(false)]
        public DateTime LastUpdatedOn { get; set; }
     
     
        public event PropertyChangedEventHandler PropertyChanged;
     
    }
  2. Mike
    Mike avatar
    10 posts
    Member since:
    Sep 2014

    Posted 17 Dec 2018 in reply to Mike Link to this post

    Submitted Support Ticket
  3. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1887 posts

    Posted 18 Dec 2018 Link to this post

    Hello Mike,

    Consider using the MultiSelectFor helper in order to wire the MultiSelect to the model field:
    @(Html.Kendo().MultiSelectFor(m => m.OrderTypeIDs)
    //...additional configuration
    )


    You can find a sample runnable MVC project, which demonstrates this approach attached to Atanas' post in the following forum thread.

    Regards,
    Ivan Danchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top