0

passing in something like "hi person" into the value of a textbox using either Html.TextBoxFor or Html.EditorFor

unfortunately the value isn't being Html Encoded.. can anyone explain why this is the case and is it fixed in MVC4..

i know you can do something like @Html.TextBox("Description", Server.HtmlDecode(Model.Description)) but is there an out of the box Html Helper that actually just encodes for you?

2
  • Post you code and make your question more clearer Commented Aug 23, 2012 at 0:07
  • 1
    You should not be encoding/decoding when using those helpers, or the values they will cause to be submitted to the server. Doing so will cause over-encoding/over-decoding, and the loss of hair. There is nothing to be 'fixed' in MVC4 here. Commented Aug 23, 2012 at 0:08

2 Answers 2

1

Html.TextBoxFor does html-encode the value - it uses the TagBuilder class underneath, which does the encoding.

I'm not sure what you're expecting for "hi person", there are no characters in that string that would change when its encoded.

Sign up to request clarification or add additional context in comments.

Comments

1

There is no need to encode/decode when dealing with the values being used in those HTML helpers, or when those values are returned to the web server on POST. That is all handled by the frameworks.

Comments

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.