Incorrect HTML coding in ASP.NET MVC?

I am using asp mvc 3. When I create my views using the default html helpers, there is a problem with html coding in tag attributes: "More than" -sign is not encoded.

So this code

<%: Html.TextBox("TestText", "<Test>") %>

produces this conclusion

<input id="TestText" name="TestText" type="text" value="&lt;Test>" />

Is there a reason why the value attribute is not complete, or is this an error? Or is there a way to use full encoding even in tag attributes?

Thanx, Michael

+3
source share
2 answers

You misunderstood the tag <%:. The tag <%:only encodes a normal one string, not HtmlStringhow the header is returned Html.TextBox.

Example:

<%: Html.TextBox("TestText", "<Test>") %>
<%= Html.TextBox("TestText2", "<Test>") %>

Both operators return the same text value as indicated in the question. Now consider this statement.

<%: "<Test>" %>

, .

EDIT:

MVC, HttpUtility.HtmlAttributeEncode . , HTML.

+3

"< > " HTML. → , </p>

+1

Source: https://habr.com/ru/post/1792071/


All Articles