How do I render HTML from the Viewbag using MVC3 Razor

后端 未结 2 681
不思量自难忘°
不思量自难忘° 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.

提交回复
热议问题