I'm setting up a simple (I thought) calculator app whereby a user enters some info into a form, and I calculate the rest of the parameters. I have two controller methods (shown below). Obviously, in this case, I am simply trying to hard change an attribute
and pass it to the appropriate view. The Views are just auto-generated Create and Edit views, respectively.
The DesignInput form is wired to call the DesignResult method, and this is, in fact, working. However, the 2nd attribute assignment never seems to update/override/replace the incoming attribute, so the Design Result View always displays the values input
in the Design Input View. How the bloody heck do I change those incoming values into something useful?
Function DesignInput() As ActionResult
Dim diffpair As DiffPair = New DiffPair
diffpair.CoaxImpedance = 10
Return View(diffpair)
End Function
<HttpPost()>
Function DesignResult(diffpair As DiffPair) As ActionResult
'perform calculations here
diffpair.CoaxImpedance = 100
Return View(diffpair)
End Function
The posted parameters takes precedence over values set by you ( good for showing error when user put 'aaa' into an input corresponding to a numeric value)
SilV3RSix
Member
9 Points
5 Posts
How to update viewmodel object
Mar 21, 2012 01:57 PM|LINK
I'm setting up a simple (I thought) calculator app whereby a user enters some info into a form, and I calculate the rest of the parameters. I have two controller methods (shown below). Obviously, in this case, I am simply trying to hard change an attribute and pass it to the appropriate view. The Views are just auto-generated Create and Edit views, respectively.
The DesignInput form is wired to call the DesignResult method, and this is, in fact, working. However, the 2nd attribute assignment never seems to update/override/replace the incoming attribute, so the Design Result View always displays the values input in the Design Input View. How the bloody heck do I change those incoming values into something useful?
Function DesignInput() As ActionResult Dim diffpair As DiffPair = New DiffPair diffpair.CoaxImpedance = 10 Return View(diffpair) End Function <HttpPost()> Function DesignResult(diffpair As DiffPair) As ActionResult 'perform calculations here diffpair.CoaxImpedance = 100 Return View(diffpair) End Functionignatandrei
All-Star
135100 Points
21675 Posts
Moderator
MVP
Re: How to update viewmodel object
Mar 21, 2012 02:00 PM|LINK
ModelState.RemoveKey("CoaxImpedance")
The posted parameters takes precedence over values set by you ( good for showing error when user put 'aaa' into an input corresponding to a numeric value)
SilV3RSix
Member
9 Points
5 Posts
Re: How to update viewmodel object
Mar 21, 2012 02:22 PM|LINK
Wow. Simple fix. Thanks.
For reference, I just called ModelState.Clear() just to clean sweep the whole shootin' match.