Alex Rivera | Logout

ASP.Net MVC 4's WebAPI does not bind check boxes correctly?

Asked 2012-08-16T22:21:52.720
9

I'm incorporating WebAPI into my development and am Posting all form submissions to a WebAPI controller. I've noticed that checkboxes are not getting bound to the model correctly. I have a form using:

@Html.CheckBoxFor(m => m.HasVideo)

It produces a checkbox and a hidden form element. When I check the checkbox (meaning a "true" value), the model binding in my WebAPI Post reflects a false for the HasVideo property. I moved the entire method over to a traditional mvc controller, and the binding works as expected.

Is there a workaround for this, or is there something that I'm missing?

Edit
Report

1 Answer

0

Seen this issue before and its usually ViewData/ViewBag interference which is a nightmare to debug usually.

You can add a ViewBag.Clear/ViewData.Clear in the function which is giving you an issue.

Cheers, J

answered 2013-02-03T17:30:03.197

Your Answer