Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC post not populating the model

I cannot figure out why my model is not being populated. All the data posted is in the Request.Form, but the model is actually turning out to be null.

According to this answer on model with collection not populating on postback

In other words, (...) If any required fields are missing, or if the values are submitted in such a way that they cannot be converted to the type of a required field, then the entire object will be left null

I have changed several value types, but I cannot get it to work.

Here is my model:

public class AddModel
{
    //Get properties 
    public Vehicle vehicle; 

    //Post properties 
    [Required(ErrorMessage = "Please enter a start date")]
    public DateTime StartDate; 
    public int? StatusCode; 

    public SelectList StatusCodes()
    {
         ...
    } 
}

Can you think of why it's not being populated?

like image 694
LocustHorde Avatar asked Feb 24 '23 01:02

LocustHorde


1 Answers

Making AddModel members Properties - adding get; set; to fields should solve your problem

like image 170
archil Avatar answered Mar 04 '23 10:03

archil