How do I render HTML from the Viewbag using MVC3 Razor

后端 未结 2 682
不思量自难忘°
不思量自难忘° 2020-12-24 11:15

I am trying to pass a form element into an MVC3 view by using the Viewbag and simply write the HTML to the page ...

In controller:

ViewBag.myData = \         


        
相关标签:
2条回答
  • 2020-12-24 12:03

    This should do the job

     @Html.Raw((String)ViewBag.myData)
    

    MSDN: This method wraps HTML markup using the IHtmlString class, which renders unencoded HTML.

    You need to be careful with accepting and displaying un-encoded HTML.

    0 讨论(0)
  • 2020-12-24 12:17

    Use @Html.Raw(ViewBag.Mydata).

    0 讨论(0)
提交回复
热议问题