2013-06-05 42 views
0

我有一個列表,其中包含很多html標記,如<input>,<select><td>。我的問題是渲染這些值時,它只是打印出它的正常值不爲HTML標籤:如何呈現將html標記保存爲字符串值的列表字符串

Where a part of that its render

  • 代碼:

    @foreach(在ViewBag VAR場點域) {

    @field 
    } 
    
  • 我已經牛逼裏德這很好,但都呈現相同的:

    @foreach(var field in ViewBag.Fields) 
    { 
    
        @Server.HtmlEncode(field); 
    } 
    
  • 而且

      @foreach(var field in ViewBag.Fields) 
         { 
    
          @Html.Encode(field); 
         } 
    

但這裏的結果:

Still not work

我應該怎麼做,使之工作?任何建議?

+1

嘗試是這樣的:http://stackoverflow.com/questions/1249018/what-is-the-equivalent-of-the-文字標籤在asp-net-mvc – emd

+2

@emd - 自2009年以來MVC發生了相當大的變化。 – Oded

+0

不知道爲什麼選擇peope。 – Ligth

回答

6

你是HTML編碼值 - 這就是爲什麼你得到它們輸出爲編碼HTML(這也是安全默認的剃鬚刀)。

使用Raw helper輸出HTML未編碼:

@Html.Raw(field); 
+0

謝謝,這按預期工作! – Ligth