views:

41

answers:

1

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.)

+3  A: 

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;}
} 
Paul Hadfield
D*mn! I told you it was box-of-rocks-stupid! Thanks, Paul.
Dave Hanna
Haha, just glad I'm not the only one - I won't say how long I struggled with it for at the time.
Paul Hadfield