Banshee
Banshee

Reputation: 15807

Strange Razor behavior?

I have the following code in my partial view of a ASP.NET MVC project :

@if (Model.Url != null && Model.Url.Length > 0)
{ <a href="@Model.Url" target="_blank" title="Besök extern sida"><img src="~/Content/Theme/images/icons/link_13x13.jpg" alt="Extern länk" /></a>  }
else
{<img src="~/Content/Theme/images/icons/link_13x13_inactive.jpg" alt="Extern länk saknas" />}

This works great!

But then I got this :

@if(!Model.PersoanlTagStatus.HasValue)
{ <div class="postContainer"> }
else if(Model.PersoanlTagStatus == ProjectX.Models.TagTypeKey.Ignore)
{ <div class="postContainer postConIgnore"> }
else if(Model.PersoanlTagStatus == ProjectX.Models.TagTypeKey.Favorite)
{ <div class="postContainer postConFav"> }

And this is not working at all? It complains at the if that it is missing its }?

Why?

Upvotes: 1

Views: 70

Answers (2)

Hamid Reza
Hamid Reza

Reputation: 2973

Use this:

@{
    if(!Model.PersoanlTagStatus.HasValue)
    {
    @<div class="postContainer"></div> 
    }
    else if(Model.PersoanlTagStatus == ProjectX.Models.TagTypeKey.Ignore)
    {
    @<div class="postContainer postConIgnore"></div>
    } 
    else if(Model.PersoanlTagStatus == ProjectX.Models.TagTypeKey.Favorite)
    {
    @<div class="postContainer postConFav"></div> 
    }
}

Upvotes: 0

Dave Alperovich
Dave Alperovich

Reputation: 32490

Try this

@if(!Model.PersoanlTagStatus.HasValue)
{ 
   @: <div class="postContainer"> 
}
else if(Model.PersoanlTagStatus == ProjectX.Models.TagTypeKey.Ignore)
{ 

   @: <div class="postContainer postConIgnore"> 
}
else if(Model.PersoanlTagStatus == ProjectX.Models.TagTypeKey.Favorite)
{ 

   @: <div class="postContainer postConFav"> 
}

Upvotes: 2

Related Questions