Hello,
I have a grid edits in pop up:
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("RecordViewModelTemplate"))
The fields bind well to the model in the template when I do:
<div class="form-group">
<label asp-for="@Model.AnimalId"></label>
<input asp-for="@Model.AnimalId" class="k-textbox" />
<span asp-validation-for="@Model.AnimalId" class="text-danger k-invalid-msg" data-for="AnimalId"></span>
</div>
However, the fields don't bind to the model when I try:
@Html.CheckBoxFor(m => m.SampleTestPackage.biochemistry[1].Selected, new Dictionary<string, object> { { "class", "biochemistry" }, { "data-test", "Comprehensive" } })
If the value is true in the model the check box doesn't appear selected.
I have tried also:
<h5> BIOCHEMISTRY </h5>
<div class="row">
@{ for (int i = 0; i < @ViewBag.biochemistry.Count; i++)
{
var biochemistryId = String.Format("biochemistry{0}", @ViewBag.biochemistry[i].Value);
<div class="form-group col-4">
<div class="custom-control custom-checkbox">
@Html.HiddenFor(m => m.SampleIndividualTest.biochemistry[i].Value)
@Html.HiddenFor(m => m.SampleIndividualTest.biochemistry[i].Text)
<input type="checkbox" id=@biochemistryId class="biochemistry custom-control-input" asp-for="@Model.SampleIndividualTest.biochemistry[i].Selected">
<label for=@biochemistryId class="custom-control-label"> @Html.Raw(@ViewBag.biochemistry[i].Text)</label>
</div>
</div> } }
</div>
but the check boxes don't bind and remain false when they are true/selected in the model.
If I do:
@{
if (Model == null){
<span> Model is empty </span>
}
}
I get as result that the model is empty.
I don't understand why some fields like AnimalId bind to the model and other no - when the model is apparently empty.
I am not coding anything to bind the model the template - is there any code I need to bind the model to the template when the edit event is clicked in the grid?
Also, when the update event is fired, the control gets and empty model, I suppose that it is logic as the model is empty.
Any help is appreciated, I suppose that I am missing the concept.
Kind Regards.