Okay, this has got to be something stupid-as-a-box-of-rocks that I'm doing wrong, but I can't find it.
MVC Action:
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult Create(BatchCreateViewModel createModel)
{
return RedirectToRoute(MVC.Home.Display());
}
BatchCreateViewModel:
public class BatchCreateViewModel
{
bool searchAVM;
bool searchBPO;
bool searchAppraisal;
int transactionAge;
string Description;
string uploadfile;
}
There are controls on the View page named "searchAVM", "searchBPO", "searchAppraisal", (checkboxes) "transactionAge"(a set of radio buttons with integer values) and "description" (a text box)
When I break at the entry to "Create", createModel is there, but has all default values(null for the strings, false for the booleans, 0 for the int). If I examine Request.Form, the values are there, but they are just not getting into the model.
What am I doing wrong?
(This is under MVC 2, Framework 4.)
Your view model should have automatic properties, not public variables. It's caught me out before!
So it should be:
public class BatchCreateViewModel
{
public bool searchAVM {get;set;}
public bool searchBPO {get;set;}
public bool searchAppraisal {get;set;}
public int transactionAge {get;set;}
public string Description {get;set;}
public string uploadfile {get;set;}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With