lundi 26 janvier 2015

MVC5 Can't validate checkbox or even get value

I use view model for my view (Razor) page and a model to save result in database. In both model and view model I have declared bools for checkboxes.



public bool Faza1 { get; set; }
public bool Faza2 { get; set; }


In my view I make checkboxes with CheckBoxFor.



@Html.CheckBoxFor(model => model.Faza1)
@Html.CheckBoxFor(model => model.Faza2)


When I try to submit my form, if checkboxes are unchecked, in model I get bools Faza1 and Faza2 equals false (it is ok), but if I check any of checkboxses again get false value and error in ModelState.IsValid in my ActionResult in controller. Does anyone know what's happening?


BTW I use Ajax form for submitting.



@using (Ajax.BeginForm("Sacuvaj",
new AjaxOptions
{
HttpMethod = "post",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "mreza",
OnSuccess = "snimljeno"
}))


{





Aucun commentaire:

Enregistrer un commentaire