HttpUtility – Encode ve Decode

        public ActionResult Index()
        {
            string isim = "<p><b>Yakup KALEBAŞI</b></p>";
            string htmlEncode = HttpUtility.HtmlEncode(isim);
            string htmlDecode = HttpUtility.HtmlDecode(htmlEncode);
            ViewBag.HtmlBaslik = htmlEncode;
            ViewBag.HtmlBaslik2 = htmlDecode;

            return View();
        }

 

<div>
    Encode : @ViewBag.HtmlBaslik
    <br/>
    Decode : @ViewBag.HtmlBaslik2
    <br/>
    <br/>
    Encode Html.Raw : @Html.Raw(ViewBag.HtmlBaslik)
    <br/>
    <br/>
    Decode Html.Raw : @Html.Raw(ViewBag.HtmlBaslik2)
    <br/>
    Decode Html.Raw : @MvcHtmlString.Create(ViewBag.HtmlBaslik2)
</div>
Index
Encode : &lt;p&gt;&lt;b&gt;Yakup KALEBAŞI&lt;/b&gt;&lt;/p&gt; 
Decode : <p><b>Yakup KALEBAŞI</b></p> 

Encode Html.Raw : <p><b>Yakup KALEBAŞI</b></p> 

Decode Html.Raw :
Yakup KALEBAŞI


Decode Html.Raw :
Yakup KALEBAŞI

 

Bunlar da hoşunuza gidebilir...