2011-05-31 124 views
0

關閉默認編碼

<%= Html.TextArea("PostContent.Description", Model.PostContent.Description)%> 

,如果我默認輸入

"I am <script>alert()</script> After scrip", 


I will get<p>I am &lt;script&gt;alert()&lt;/script&gt; After scrip</p> 

但我不希望這種行爲。我怎樣才能關閉此默認行爲只爲這個文本框

請注意,我只是想處理這個文本框只。

[MVC 2]

回答

1

試試這個:

<textarea name="<%= HtmlHelper.GenerateIdFromName("PostContent.Description") %>"> 
    <%= Model.PostContent.Description %> 
</textarea> 
+0

這不起作用:( – 2011-06-02 06:35:37

3

爲了防止粘合劑逸出HTML字符,你可以標記Description財產與[AllowHtml]屬性:

public class ModelPostContent 
{ 
    [AllowHtml] 
    public string Description { get; set; } 
} 
+0

這是在mvc3 – 2011-05-31 12:17:49

+0

可用哎呀,我沒有檢查MVC版本。太糟糕了,我從MVC 3開始,並沒有學到微妙之處 – Zruty 2011-05-31 12:42:16

0

我發現不可能通過mvc避免默認編碼