I have a controller-action with a complex object for input parameter, which is sent by a Post.
In a scenario I wouldn’t want the user submit something valid (for example he pressed a back button), but I still want to persist the state of the form, so I put it in the Session.
There is a property on the VM called Valid for marking the result of the modelstate validation for later use.
I wouldn’t want the user to somehow send this property from clientside (for example setting it to a false positive state could confuse my code if I’m not careful).
Is there an attribute, like non-serializable to be used here? (So I wouldn’t have to explicitly set it to false it in my code).
Part of my code (most of it is ripped out)
[HttpPost]
public ActionResult FormWithDelayedValidation(MyVM vm)
{
SessionVariables.Current.OrderSecondVM = vm;
if (ModelState.IsValid)
{
vm.Valid = true;
return Redirect(somewhere);
}
if (vm != null) vm.Valid = false;
return Redirect(somewhere_else);
}
You could use BindAttribute to control properties used when model binding.