3

HTML テキストを my に渡そうとしていますdiv。この文字列を HTML 要素としてレンダリングする必要があります。私のコード:

<div id="divchat" style="width: 500px; height: 300px; border: 2px solid brown;"/></div>
@Html.TextBoxFor(model => model.msj) 
<button type="submit" id="btnSend">Send</button>

<script>
    $(function(){
          var chatNS = '@HttpContext.Current.Application["Chateo"].ToString()';
          $("#divchat").append(chatNS);
    });
</script>

divは文字列のようにコンテンツを表示していますが、HTML 要素を正しくレンダリングするにはどうすればよいdivchatですか?

4

2 に答える 2

2

でラップHttpContext.Current.Application["Chateo"]してみました@Html.Raw()か?

<script>
    $(function(){
      var chatNS = '@Html.Raw(HttpContext.Current.Application["Chateo"])';
      $("#divchat").append(chatNS);
    });
</script>
于 2013-04-08T07:06:54.243 に答える