tags:

views:

27

answers:

2

I have a view where a supervisor selects if something is approved or not and enters a comment. Most of the fields are not displayed for this view. The view is strongly typed.

I was curious how I can return the whole object back to the controller. It appears like it just returns the fields I have on the form.

+2  A: 

Either store all of the extra data in hidden input fields on the page, or store the id of the item in a hidden field and load the object from your repository on every page load (my preferred method).

EDIT: You could also make another object with fewer parameters, and only send the scaled down object to the view, which would return fully populated and could then be mapped back to the full object (a more MVVM approach).

NickLarsen
OMG! I must really be dense... I didn't think of storing the ID. Nose too deep in the code apparently. Thanks!
Mike Wills
@Mike Wills: Happens to everyone. GL with your system.
NickLarsen
A: 

Put it back in the same way as you put it in the view. You don't have to post data you already have.

public ActionResult Get()
{
   var viewModel = constructViewModel();
   return View(viewModel);
}

public ActionResult Post(ViewModelChanges changes)
{
  var viewModel = constructViewModel();
  viewModel.SomeProperty = changes.SomeProperty;
  return View(viewModel);
}
Paco