Skip to content Skip to sidebar Skip to footer

Html Encode Decode C# Mvc4

I am in a process of upgrading a c# MVC2 project into c# MVC4. Here is the scenario in MVC2 Input string(from database) Model.text='

Hihello!you ther

Solution 1:

This should do the trick:

@Html.Raw(Model.text)

Solution 2:

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.

Solution 3:

In controller side

viewbag.msg="hello";

in the html.cs razor view

@Html.Raw(viewbag.msg)

Post a Comment for "Html Encode Decode C# Mvc4"