asp.net mvc - MVC encodig strings -


i set validateinputattribute in controller action false. in view, have textbox:

<p>     <%= html.textboxfor(m => m.name.lastname, new { maxlength = "100" })%>      <%= html.validationmessagefor(m => m.name.lastname) %>     <%= html.hidden("hiddenlastname", model.name.lastname) %> </p> 

now can save thourgh textbox, when displaying data see strange characters. when save <script>alert(“boo!”)</script> , open site again see result, see: <script>alert(“boo!”)</script>

how can fix this?

note: i'm not encoding input somewhere else in code.

if want see < instead of &lt;, use httputility.htmldecode

if you're saving user input in database , want them allow entering html, encode input in controler before storing in database:

model.input = httputility.htmlencode(model.input); 

and when want dispaly input, decode in in view:

@httputility.htmldecode(model.input) 

and instead of setting validateinputattribute false, use [allowhtml] attribute input property in model:

[required] [allowhtml] public string input {get; set;} 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -