开发者

Return all fields from strongly typed object from View in MVC

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.


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


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜