Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML not rendering inside Razor if

I have inside a view file something like

 @Html.ActionLink("Details", "Details", new { id=item.RuleId }) |                     
  @Html.ActionLink("Edit", "Edit", new { id = item.RuleId }) |
  @Html.ActionLink("Delete", "Delete", new { id = item.RuleId })

and this works, but when I change it to something like

 @Html.ActionLink("Details", "Details", new { id=item.RuleId }) |

     @if( something )
  {                
  Html.ActionLink("Edit", "Edit", new { id = item.RuleId });
  Html.ActionLink("Delete", "Delete", new { id = item.RuleId });
  }     

it stops displaying the second and third items ( although is entering the branch ) .

Any ideas why ?

like image 725
coredump Avatar asked Jan 25 '26 04:01

coredump


1 Answers

Html.ActionLink returns an IHtmlString object containing an <a> tag.
It doesn't do anything by itself.

Your code is ignoring this result, so nothing happens.

You need to print the result to the page using the @ character.

like image 74
SLaks Avatar answered Jan 26 '26 16:01

SLaks