This is a migrated thread and some comments may be shown as answers.

MultiSelect always returns null as Editor Template

2 Answers 573 Views
MultiSelect
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 13 Dec 2018, 09:06 PM

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 Answers, 1 is accepted

Sort by
0
Mike
Top achievements
Rank 1
answered on 17 Dec 2018, 11:12 PM
Submitted Support Ticket
0
Ivan Danchev
Telerik team
answered on 18 Dec 2018, 02:54 PM
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.
Tags
MultiSelect
Asked by
Mike
Top achievements
Rank 1
Answers by
Mike
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or