Html encoding with TextBoxFor MVC 4

江枫思渺然 提交于 2019-12-11 11:36:56

问题


Whenever I enter anything in < angle brackets > (as well as some other html syntaxy things) into my TextBoxFor an exception is thrown

@Html.TextBoxFor(model => model.tags, new { @class = "form-control", placeholder = "tags (comma separated)" })

A potentially dangerous Request.Form value was detected from the client (tags="").

I understand this occurs to prevent insecurities and that html encoding/decoding is the solution to my issue but I'm not sure how to implement it.

I've read in a few places that TextBoxFor does html encoding by default, but if that's true why am I having this issue?


回答1:


To prevent this warning your have to put the [AllowHtml()] attribute on the tags property of your viewmodel.



来源:https://stackoverflow.com/questions/24943455/html-encoding-with-textboxfor-mvc-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!