user3609351
user3609351

Reputation: 169

kendo multiselect for mvc clears the selected values on submit

My kendo multiselect control as displays below clears the selected values on page submit. When i submit the page and it contains validations errors, the selected items in the multiselects get lost. Even though its gets fill in the HttpPost method of the controller. Please help me find a solution for this behaviour.

@(Html.Kendo().MultiSelectFor(m => m.GemeentesIds)                  
    .HtmlAttributes(htmlAttrMultiselect)
    .DataTextField("Name")
    .DataValueField("Id")
    .Placeholder(Model.Disabled ? "" : "Selecteer gemeentes indien van toepassing...")
    .Value(Model.Gemeentes)                                 
    .AutoBind(false)
    .DataSource(source => {
        source.Read(read => {
             read.Action("GetGemeentes", "General").Data("GemeenteFilter").Type(HttpVerbs.Post);
        })
        .ServerFiltering(false);
    })
                                            )

Controller:

if (model.GemeentesIds != null)
    model.Gemeentes = _organisatorischeEenheidRepository.GetGemeentesByIds(model.GemeentesIds);

Upvotes: 0

Views: 1189

Answers (1)

Sudhir
Sudhir

Reputation: 421

Try this and see if it helps. Also assign a Name attribute using Name() method.
In your case, I think it should be Gemeentes.
So your multi-select code would look like:

@(Html.Kendo().MultiSelectFor(m => m.GemeentesIds)  
    **.Name("Gemeentes")**                
    .HtmlAttributes(htmlAttrMultiselect)
    .DataTextField("Name")
    .DataValueField("Id")
    .Placeholder(Model.Disabled ? "" : "Selecteer gemeentes indien van toepassing...")
    .Value(Model.Gemeentes)                                 
    .AutoBind(false)
    .DataSource(source => {
        source.Read(read => {
             read.Action("GetGemeentes", "General").Data("GemeenteFilter").Type(HttpVerbs.Post);
        })
        .ServerFiltering(false);
    })
)

Source link which helped me resolve a similar issue: http://www.telerik.com/forums/multiselect-and-form-not-sending-values-back

Upvotes: 1

Related Questions