开发者

MVC.Net HTML Encoding, IE7 vs other browsers

开发者 https://www.devze.com 2023-02-04 12:36 出处:网络
When I have this in my view <a href=\"../Product/Category/<%= Html.Encode(item.Category) %>/Default.aspx?partial=False\">

When I have this in my view

<a href="../Product/Category/<%= Html.Encode(item.Category) %>/Default.aspx?partial=False">
    <%= Html.Encode(item.Category)%></a>

It renders as expected in IE8 & FF

<a href="../Product/Category/Sauces%20&amp;%20Toppings/Default.aspx?partial=False">
    Sauces &amp; Toppings</a>

but does not render correctly in IE7

<a href="../Allergen/Category/Sauces &amp; Toppings/Default.aspx?partial=False">
    Sauces &amp; Toppings</a>

Specifically, it appers IE7 is decoding the href property value.

How do I 开发者_运维技巧get IE7 to render the encoded href?


You're using the wrong encoding.

You need to call Html.AttributeEncode(Url.Encode(item.Category)).

0

精彩评论

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