-1

I send my viewmodel from my get action method to a view for update, the view has a submit button which takes returns control to the post action method. The viewmodel is of this form

public class MyViewModel
{
   public someObject a;
   public someOtherObject b;
}

Now, in the get method someOtherObject b has data in it, in the view it has data in it, but in the post method it is null. Why might this be?

Thanks,

Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304

1 Answers1

1

Without looking into it in too much detail, I'd take a guess at the problem being that your model has fields instead of properties. Try this instead:

public class MyViewModel
{
   public someObject a { get; set; }
   public someOtherObject b { get; set; }
}

The default MVC model binder examines your model for settable properties (hence the overridable SetProperty() method taking a PropertyDescriptor) and sets those values, so I'm guessing that fields are ignored.

Steve Wilkes
  • 7,085
  • 3
  • 29
  • 32