HTML encode decode c# MVC4

前端 未结 3 529
渐次进展
渐次进展 2020-12-15 07:04

I am in a process of upgrading a c# MVC2 project into c# MVC4.

Here is the scenario in MVC2

Input string(from database)

   M         


        
相关标签:
3条回答
  • 2020-12-15 07:13

    In controller side

    viewbag.msg="hello";
    

    in the html.cs razor view

    @Html.Raw(viewbag.msg)
    
    0 讨论(0)
  • 2020-12-15 07:17

    If you don't want your text get encoded, that text should be of type IHtmlString. String texts are encoded by default.

    In your case,

    Model.text = MvcHtmlString.Create("<p>Hi<br>hello!<br>you there</p>");
    

    would do the trick as well.

    0 讨论(0)
  • 2020-12-15 07:31

    This should do the trick:

    @Html.Raw(Model.text)
    
    0 讨论(0)
提交回复
热议问题