0
votes

I have Kendo MVC Grid with Popup Editor template. I need to add Checkbox list for a model property. This is what I am doing

I declared a property in my view model like this...

public List<string> Category { get; set; }

This is how I am declaring Checkboxes in view

<ul>
  @foreach (var g in (MultiSelectList)ViewData["BondPermitTypes"]) {
  <li class="checkbox">
    <label>
      <input type="checkbox" name="Category" class="checkbox-removekvalid" id="[email protected]" value="@g.Value.ToString()" />@g.Text
    </label>
  </li>
  }
</ul>

This code is working fine when I edit the existing records...

The problem is when I try to create new record and select any checkbox, all of the checkboxes are getting checkedenter image description here

Moreover, even if I hack around using jquery and force it to check only selected checkboxes then when I post back the "Category" property has only one string all the time, which is "true".

I appreciate your help!

1
@saquib_adil: did you get this working? Please post your solution if you did.callisto

1 Answers

0
votes

Sorry for the late reply...

To make it work, I have added the default value for the Category property in the Kendo Grid. Like this

.Model(model =>
        {
            model.Id(p => p.PkProperty);
            model.Field(p => p.Category).DefaultValue(new List<string>());
        })

Hope it helps you! :-)