Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional link in Razor

I have some tabs, and I want to say "if they are currently on the page that this tab refers to, make this a span. Otherwise, make this a link." In pseudo-razor, that would look like this:

@if(CurrentlyOnThisPage) {
  <span>
} else {
  <a>
}
   Tab Content
@if(CurrentlyOnThisPage){
  </span>
} else {
  </a>
}

Razor (correctly) notes that I'm not closing my beginning tags, and so has trouble parsing this syntax. If the tab content was small, I could use Html.ActionLink, but I've got a few lines of stuff and I'd like to keep the benefits of the HTML editor rather than putting it all into a string. Is there any way to do this?

like image 436
Xodarap Avatar asked Dec 04 '22 23:12

Xodarap


1 Answers

You can write the tags as literal text to prevent Razor from parsing them:

@:<span>
like image 90
SLaks Avatar answered Dec 26 '22 20:12

SLaks