I have the following ViewModel
public class ReportFilters
{
[Required]
public DateTime From { get; set; }
[Required]
public DateTime To { get; set; }
[Required]
public int UserId { get; set; }
public bool IsCorrect { get; set; }
}
I pass either the value 1 or 0 when I call this route to IsCorrect but the ModelState.IsValid is always returning false.
This started to happen after I added public bool IsCorrect { get; set; }
Here is how my controller action look like
[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult GetTotals([Bind(Include = "From,To,UserId,IsCorrect ")] ReportFilters reportFilters)
{
if (ModelState.IsValid)
{
SomeModel results;
if(reportFilters.IsCorrect)
{
results = conn.Database.SqlQuery<SomeModel>(SomeQuery, from, to).ToList();
} else
{
results = conn.Database.SqlQuery<SomeModel>(SomeOtherQuery, from, to).ToList();
}
return Json(results, JsonRequestBehavior.AllowGet);
}
return Json(new { }, JsonRequestBehavior.AllowGet);
}
Question
How can I correctly validate the value of a check box? If the value is 1 then it should be true otherwise false.

[Bind(Include = "From,To,UserId,IsCorrect ")], and try again?