Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Help figuring out 5 levels of @ indirection on Razor page

$
0
0

My code reads a website field from a database.  The field's values are things likewww.google.com, www.bing.com etc without the preceding http:// (orhttps://).

The MVC model returns and displays this field correctly, but I can't get it to prepend http:// and then make the entire thing clickable.

This is the code I have:

@foreach (var item in Model) {
<tr>
   <td>
   @if (item.PrimarySiteName != null)
   {
      @Html.Raw(@("http://" + @item.PrimarySite))
   }
   </td>

</tr>

}

Without the @Html.Raw, the field actually displays correctly, but this code doesn't even run.  Maybe I need to use <a href=""> to wrap the prepended string.  Depending upon how I mess with the code, sometimes the double slash is interpreted as a comment ( when I use @{ } for example ).  How can I get this link to display and be clickable?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>