views:

45

answers:

2

Update following initial comments

The model has an object in it called 'Account', of which there is an int propety (Account.AccountID)

ViewB has a form which collects some additional information - but also has a textbox which is populated with Model.Account.AccountID.

When I submit ViewB however, Model.Account becomes null.


Its probably easier to show a simplified version of what I have before I explain the issue:

[HttpGet]
public ActionResult ViewA()
{
  return View(new BlahModel());
}

[HttpPost]
public ActionResult ViewA(BlahModel model)
{
  if(there_was_a_problem)
    return View("ViewA", model);
  else
    return View("ViewB", model);
}

// have tried both httppost, httpget and no attribute here
public ActionResult ViewB(BlahModel model)
{
 return View(model);
}

I load up ViewA via a GET, fill in the strongly-typed form and submit - then the following View (either ViewA again or ViewB if the request had no problems) is fine ... it has full access to the whole model and can display the properties within it.

The problem is that if I then submit a form in ViewB (which posts to the ActionResult ViewB) - the model suddenly has null properties throughout, even though its using the same model - and prior to the post has picked up all the values sucessfully.

Any ideas?

Many thanks

+1  A: 

Most likely - ViewB view does not render enough and model binder can't find values to bind.

Action argument is binded from form values. It does not matter if You pass model to view correctly. Rendering things out is what matters (or passing through query string/cookies).

Arnis L.
Thanks so much, I checked the POST and from that then twigged that someone had set the textbox showing the AccountID to 'disabled'
beardtwizzle
+1  A: 

Complementing Arnis L.'s answer above (not enought rep points to post comments), you can use a tool like Firebug to check that your model's parameters (or any parameters at all) are being sent along the request.

dsetton