Reputation: 155
I want to make something like that:
@if ( some-statement )
{
<div class="row-link">
}
else
{
<div class="row">
}
<div class="new">some content</div>
</div>
but the compiler keeps telling me that the if has no closing character! What's wrong? Thanks!
Upvotes: 0
Views: 4541
Reputation: 13028
I'm not fluent in c# but why don't you use a variable to hold the classname?
@string classname;
@if ( some-statement ) {
classname = "row-link";
} else {
classname = "row";
}
<div class="@classname">
<div class="new">some content</div>
</div>
Or you could use a helper function. It keeps your html cleaner.
Upvotes: 4
Reputation: 19217
You may consider closing your <div>
and remove your common end </div>
@if ( some-statement )
{
<div class="row-link"></div>
}
else
{
<div class="row"></div>
}
<div class="new">some content</div>
Upvotes: 0
Reputation: 471
try
@if ( some-statement )
{
@:<div class="row-link">
}
else
{
@:<div class="row">
}
<div class="new">some content</div>
</div>
Upvotes: 1
Reputation: 60486
Use <text>
@if ( some-statement)
{
<text>
<div class="row-link">
</text>
}
else
{
<text>
<div class="row">
</text>
}
<div class="new">some content</div>
</div>
and check out
http://weblogs.asp.net/scottgu/archive/2010/12/15/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax.aspx
hope this helps
Upvotes: 2