1

I have this:

model.PasswordField = null;
return View("MainLogin", model);

My model contains LoginField and PasswordField. I leave LoginField untouched, but I erase PasswordField. Now, when MainLogin view is rendered, the field password has a value from my previous request! Why?

Update: Added my view code:

<div class="editor-field">
                @Html.TextBoxFor(model => model.PasswordField, new { placeholder = "Password" })
                @Html.ValidationMessageFor(model => model.PasswordField)
            </div>
1
  • please include your view in post Commented Feb 23, 2013 at 21:46

2 Answers 2

2

You are changing the value in the Model but the HtmlHelper methods check the ModelState first to display the value, on postback. This is by design. To display the modified value, you need to clear the ModelState using,

ModelState.Clear();
Sign up to request clarification or add additional context in comments.

Comments

0

in the load of your form you can create a function clean() where you put an initialization of field you want to be empty for example

clean()
{

textlabel.setvalue="enter text ";
field1.empty();

passwordField.empty();
}

6 Comments

then at the start of your form the function initialize part of your field
Well that's cool, thanks for that. But anyways, I am looking for the answer why is that value in my view, it shouldn't!
perhaps they keep the value like a default value of the password field look at the value at the property field
@Benius, while I wouldn't rule it out, this seems like blind guessing.
@Benius: It is highly unlikely, since i am testing this now with variety of values, and my browser would ask me if i want to keep those as default.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.