Home Encoding text in .cshtml file
Reply: 1

Encoding text in .cshtml file

jinal
1#
jinal Published in 2017-09-12 09:41:36Z

I have one .cshtml file in mvc c# I want to encode string using HttpUtility.HtmlEncode but its resulting into namespace error. Can anyone help me how i can encode this text "PICO+"?

<div id="pageTitleText">[@Model.Item.Key]
     @if (!Model.IsUserReadonly && !Model.ReadOnlyCachesList.Contains(Model.CacheName))
     {


         <span class="itemActions">
             <a class="edit" href="@Url.Content("~/caches")/@Model.CacheName/edit?key=@HttpUtility.HtmlEncode("PICO+")">Edit</a>
             <a class="clone" href="@Url.Content("~/caches")/@Model.CacheName/clone?key=@HttpUtility.HtmlEncode("PICO+")">Clone</a>
             <a id="evictItem" class="evict" href="#">Evict</a>
             <a id="deleteItem" class="delete" href="#">Delete</a>
         </span>
     }
</div>
Roberto Conte Rosito
2#
Roberto Conte Rosito Reply to 2017-09-12 10:15:54Z

You have to use @Html.Encode, I've edited your code:

<div id="pageTitleText">[@Model.Item.Key]
     @if (!Model.IsUserReadonly && !Model.ReadOnlyCachesList.Contains(Model.CacheName))
     {


         <span class="itemActions">
             <a class="edit" href="@Url.Content("~/caches")/@Model.CacheName/edit?key=@Url.Encode("PICO+")">Edit</a>
             <a class="clone" href="@Url.Content("~/caches")/@Model.CacheName/clone?key=@Url.Encode("PICO+")">Clone</a>
             <a id="evictItem" class="evict" href="#">Evict</a>
             <a id="deleteItem" class="delete" href="#">Delete</a>
         </span>
     }
</div>

I hope this can help.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.516433 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO