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 : <p><b>Yakup KALEBAŞI</b></p> 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