Model Binding not working
Just to contribute another possible reason: I've spent couple of hours looking for an error in my code and the reason for the binder not working in my case was using a model with public fields rather than public properties:
public int CustomerName;
and it should be:
public int CustomerName { get; set; }
Been working on ASP.NET MVC for 3 years now and I never came across this before. Hope it saves somebody some frustration ;)
Here's the problem:
[HttpPost]
public ActionResult Create(LocationViewModel location)
Do you see it? It's the name of your action argument: location
.
Look at your view model now, it has a property named Location
:
public Location Location { get; set; }
This confuses the model binder. It no longer knows whether you need to bind the LocationViewModel
or its property.
So simply rename to avoid the conflict:
[HttpPost]
public ActionResult Create(LocationViewModel model)