Reputation: 101150
The following code generates an error:
@Html.ActionLink("Title", "action", new { id=1 }, new { @class = "myCssClass" });
I tried to use @ since class
is a keyword. How should I write it when using razor?
Edit
The problem was not really the at sign, but that I didn't use blocks together with my if
:
@if (blabla)
@Html.ActionLink("Title", "action", new { id=1 }, new { @class = "myCssClass" });
Works:
@if (blabla)
{
@Html.ActionLink("Title", "action", new { id=1 }, new { @class = "myCssClass" });
}
Up voted both answers since they made me realize the problem.
Upvotes: 32
Views: 52385
Reputation: 1039110
Simply:
@Html.ActionLink("Title", "action", new { id=1 }, new { @class = "myCssClass" })
will work in ASP.NET MVC 3 RC2. Razor is intelligent.
Upvotes: 8
Reputation: 3236
Try to write something like:
@(Html.ActionLink("Title", "action", new { id=1 }, new { @class = "myCssClass" }));
There is a good post about Razor related to your problem: ScottGu Blog
Upvotes: 48