Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc 2 remembering my data between posts (unwanted)

i have a post method like this

[HttpPost]
public ActionResult Activatecard(ActivateCardViewModel model)

i then do things, and at the end of the method i do this

ActivateCardViewModel m = new ActivateCardViewModel();
m.Currency = partner.DefaultCurrency;
m.ActivateAmountCents = "00";
return View(m);

so, what i expected, was that the view was rendered with this new ActivateCardViewModel object, and the 2 properties filled (and shown in the view). (in the get i do the same, and it does work there)

but, as you might guess right now :) it doesn't!

it remembers (shows) everything from the posted object (model).

i hope it's by design, and someone can tell me why....

EDIT

when i post 56 cents and i put, as shown in the code, 00 cents in the new object, it still shows the 56 cents, thus it looks at it is right ignoring my new 'm' variable

like image 319
Michel Avatar asked Jan 21 '26 08:01

Michel


1 Answers

Are you using HtmlHelpers?

If the ModelState contains a key for the same name as any HtmlHelper form fields the HtmlHelpers will use the ModelState value before using the Models value. The only way to reset this is to adjust ModelState entries.

ModelState.Clear();
like image 73
John Farrell Avatar answered Jan 23 '26 04:01

John Farrell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!