I have the following POCO classes:
public class Location
{
public int LocationId { get; set; }
public string Name { get; set; }
publi
Let me add here yeat another reason why the model binder would not work properly.
I had a model with the property ContactPhone, somewhere along the way I decided to change the name of this property to Phone, then all of a sudden model binding for this property stopped working when I was trying to create a new instance.
The problem was on the Create action in my controller. I have used the default Visual Studio scaffolding and it has created the method signature as this:
public ActionResult Create([Bind(Include = "Id,ContactPhone, ...")] Customer customer)
{ ... }
Pay attention to the Bind attribute, the scaffolder created the fields using the original name ContactPhone and as this is a string, it was not refactored. As the new field Phone was not being included, it's value was ignored by the model binder.
I hope this saves someone's time.
Good luck!