views:

11

answers:

1

I have a class Foo with a field UpdateMe of type Confirmation as described below..

public class Foo
{
  public Confirmation UpdateMe{get;set;}
  public int BarInt{get;set}
}

public enum Confirmation
{
  N = 0,
  Y = 1
}

I have a whitelist that has UpdateMe, and runs the following way...

[AcceptVerbs(HttpVerbs.Post), ValidateAntiForgeryToken]
public ActionResult Update(Foo foo)
{
  if(ModelState.IsValid)
  {
    //this is the Foo as it exists in the backend..using Linq2Sql read/record behavior
    Foo existingFoo = _Service.GetFoo();
    string[] whitelist = { "UpdateMe" };

    UpdateModel(existingFoo, whitelist);

    //do persistence stuff down here...

  }
}

the model is bound just fine, the incoming Foo has whatever UpdateMe value I set, however the UpdateModel procedure is not updating the property.

This has been ridiculously simplified, but rest assured the UpdateModel is working for other properties coming through the action.

Any idea why this particular public property is not updating?

A: 

Ok, heres the scoop.

The issue is that the field was mapped to a checkbox. When not writing the checkbox using an HtmlHelper it was not propagating into the ModelState, and therefore not being included in the UpdateModel.

When I switched to using an HtmlHelper, the ModelState was then including the checkbox value regardless of being selected(desired)...however this brought back the ugliness of mapping an enum type to a checkbox.

E Rolnicki