MVC3 - Model empty on post
There are two primary ways this can happen.
One way is that you have custom model binding that is not working. I assume you are doing everything out-of-the-box so this wouldn't apply.
The most likely issue is that the data is not getting POSTed. Ensure that the fields exist inside the same Form that the Delete button is POSTing.
Had same problem. One of my properties in the model was called model
public String model { get; set; }
After renaming the property to myModel. The model object stopped coming back null in ActionResult
Ensure that your model is marking it's properties as properties (if using VB, or C# with get/set), not a public field... MVC won't map to a public field, but will to the public property.
If the parameter for the model in the [HttpPost]
Action is the same name as a property in the model it'll be null and will fail validation saying the field was invalid.
Example:
public class ContactMessage
{
public string Name { get; set; }
public string sankdmfskm { get; set; }
}
[HttpPost]
public ActionResult Index(ContactMessage sankdmfskm)
{
...
}
sankdmfskm
will be null
.
Tested in MVC3 and MVC4.