开发者

Do MVC helpers encode the Attribute Values?

ie

 new{@class="Model.Clas开发者_StackOverflows"}

?


Yes, they do encode the values. This:

new{ @class = "a&b\"c" }

will render the attribute as class="a&b"c".

However, I don't see anything in your example that needs encoding. Perhaps you mean "evaluate", in which case the answer is no. To put the value of the Class property from the Model in the object, just remove the quotation marks so that the expression is code, not a string:

new{ @class = Model.Class }


Yes. That is why I had to write my own.

Can be problematic for example in this situation:

<input type="submit" value="Unicode characters go here." />

To get rid of this behavior one should play with TagBuilder.ToString method or maybe with RouteValueCollection to possibly override their behavior. However I'd say it's simpler to quickly write your own helper using basic string concatenation operations. Result is a simple text output anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜