Asp.net MVC 3 razor code problem in if statement

I have the following asp.net mvc 3 brander code, where "item" is my model,

<a @if (item.Selected) { class="youarehere" } href="@item.Href" title="@item.Title">@item.Description</a> 

This code causes the following error:

 CS1513: } expected 

which indicates

 class="youarehere" 

part of the code, but I could not understand why. Can someone help indicate how to fix this? Thanks.

+4
source share
2 answers

Try the following:

 <a @if (item.Selected) { @:class="youarehere" } href="@item.Href" title="@item.Title"> @item.Description </a> 
+2
source

Try the following:

 <a @(item.Selected ? "class='youarehere'" : "") href="@item.Href" ... 
+4
source

Source: https://habr.com/ru/post/1335709/


All Articles