Why in the world does the line:
<%= Html.CheckBox(\"ForSale\", Model.Product.ForSale)%> For Sale
result in the following HTML:
<
Here's how I've done it in one of my apps. Frustrating, but it seems to work.
public virtual ActionResult Edit(int id, FormCollection values)
{
SomeObject dbData = _repository.GetSomeObject(id);
try
{
UpdateModel(dbData);
if (values.GetValues("CheckBoxId").Contains("true"))
dbData.SomeBooleanProperty = true;
else
dbData.SomeBooleanProperty = false;
_repository.Save();
Session["Success"] = "Successfully edited the part.";
return RedirectToAction("Index");
}
catch
{
// Handle validation errors here
return View(new SomeObjectFormViewModel(dbData));
}
}
Hope this helps. If you've got any follow-up questions, just leave a comment and I'll update my answer accordingly.