BioloMICS logo
×
BioloMICS Web Menu

U field in razor (Hyperlink)

 
 
Hyperlinks in the razor can be clickable and opening the actual link.
 
        @if (!@Model.U292.IsEmpty){ 
        <tr>
            <td>EMBL/Genbank accession nrs</td>
            <td>
                @foreach(var urlGen in @Model.U292) {
                    <p><a href="@urlGen.Url" target="_blank">@urlGen.Name</a></p>
                }
            </td>
        </tr>
        }
 
 
Extra expanation on the code:
 
  • @foreach is needed to make sure that all attached hyperlinks are displayed.
     
  • @urlVARIABLENAME actual link address taken from the value of the field.
     
  • target="_blank" opens the link in a new page.
     
 
Note that the URL in the database should be an absolute url which starts with http or https.
If that is not the case, then it can be added to the razor itself.
<p><a href="https://@urlGen.Url" target="_blank">@urlGen.Name</a></p>
 
 
The code placed in a table:
 
<table class="table">
    <thead>
    </thead>
    <tbody>
        @if (!@Model.U292.IsEmpty){ 
        <tr>
            <td>EMBL/Genbank accession nrs</td>
            <td>
                @foreach(var urlGen in @Model.U292) {
                    <p><a href="@urlGen.Url" target="_blank">@urlGen.Name</a></p>
                }
            </td>
        </tr>
        }
    </tbody>
</table>