Base solution for your next web application
Open Closed

serializeFormToObject() with checkbox / bool #5970


User avatar
0
sbenfares created

Hi,

I have a DTO & ViewModel with a boolean fields. (MyData)

I'm using a checkbox on my razor view :

<input type="checkbox" id="myCheckBox" name="myCheckBox" value="@Model.MyData" checked="@Model.MyData" />

When i try to call my service :

                        myService.myMethod($form.serializeFormToObject())
                            .done(function () {
                                // Todo notify
                            });

I have an error which explain me that the serializeFormToObject() method cannot bind checkbox string to bool :

Could not convert string to boolean: value


1 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Your input checkbox name property should be MyData

    <input type="checkbox" id="myCheckBox" name="MyData" value="@Model.MyData" checked="@Model.MyData" />