jeudi 28 janvier 2016

How to send checkbox value in remote validation

I have a form with 2 fields, a textbox and a checkbox, the textbox has jquery remote validation via Remote attribute setted in the model.

ViewModel

public class ViewModel
{
    [Remote("IsValid", "About", AdditionalFields = "Ok")]
    public string Name { get; set; }

    public bool Ok{ get; set; }
}

View

@model ViewModel
<form id="foo" action="@Url.Action("F")" method="POST">
    @Html.TextBoxFor(model => model.Name)
    @Html.CheckBoxFor(model => model.Ok)
   <input type="submit"/>
</form>

When the textbox changes remote validation is triggered but the ajax request always sends the original value of the checkbox when the page loaded no matter if it changed.

I made a test where the additional field was a textbox also and the problems doesn't occur, it seems to be a checkbox problem.

Is that a design issue of jquery remote validation? Is there a workaround to achieve this?




Aucun commentaire:

Enregistrer un commentaire