4

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

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

This code throws up the following error,

CS1513: } expected

which is pointing to

class="youarehere"

portion of the code, but I could not figure out why. Could someone help point out how to fix it please? Thank you.

2 Answers 2

4

Try This:

<a @(item.Selected ? "class='youarehere'" : "") href="@item.Href" ... 
Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

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

1 Comment

This doesn't work for me, it seems to treat the '}' as part of the '@:' =/ (and putting a '@' in front of the bracket doesn't help either.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.