asp.net mvc - Render string to html in MVC -


a similar question asked here answer did not solve problem below.

how can render string html? basically, need pass string view has "a" tag definition in it. want render actual html link clickable.

view model (simplified):

public class myviewmodel {     public string mylink { get; set; } } 

in controller (simplified):

public iactionresult index() {     myviewmodel model = new myviewmodel();      model.mylink = "<a href="http://www.google.com">http://www.google.com</a>"      return view(model); } 

in view (at first line):

@model mynamespace.viewmodel.myviewmodel 

then below, these html markups (1st lines after numbers) displays results (2nd lines). none of them actual links can click on.

1 @model.mylink &lt;a href=&quot;http://www.google.com&quot;&gt;http://www.google.com&lt;/a&gt;  2 <pre>@html.raw(@model.mylink)</pre> <a href="http://www.google.com">http://www.google.com</a>  3 @html.encode(@html.raw(@model.mylink)) &amp;lt;a href=&amp;quot;http://www.google.com&amp;quot;&amp;gt;http://www.google.com&amp;lt;/a&amp;gt;  4  @html.encode(@model.mylink) result same #3. 

any appreciated. in advance.

in controller use

model.mylink = httputility.htmldecode(url); 

then in view use

@html.raw(model.mylink) 

the first converts use


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo