Reputation: 12441
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.
Upvotes: 4
Views: 7011
Reputation: 41
Try This:
<a @(item.Selected ? "class='youarehere'" : "") href="@item.Href" ...
Upvotes: 4
Reputation: 82903
Try this:
<a @if (item.Selected) { @:class="youarehere" }
href="@item.Href"
title="@item.Title">
@item.Description
</a>
Upvotes: 2