I have a ModelA model and a strongly typed view ViewA which is typed to ModelA. As you know if you declare an action say ‘ActionAPost’ with a signature like this:
[HttpPost]
public ActionResult ActionAPost(ModelA mod) {
// code
}
It will bind the values setted on the form to ModelA instance in this case mod. I want to do something like this:
ViewA:
@ModelAInstance.SomeAttr = ViewBag.SomeAttr;
Assign some value staticaly to the model attribute that will be processed by the post action.
Edit:
The value is set on ViewBang previously.
So in the view have a hidden element where the name attribute reflects the object path of the model and property. This way it will bind back to your POST action how you want it
Example:
With Razor and the
ViewBagvalueSet the value in the Model in your
GETrequest then with razor:@Html.HiddenFor(m => m.SomeAttr, new { value = ViewBag.SomeAttr });