1

我在 ASP.NET MVC 项目的部分视图中有以下代码:

@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" />}

这很好用!

但后来我得到了这个:

@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"> }

这根本不起作用?它抱怨如果它缺少它的}?

为什么?

4

2 回答 2

2

试试这个

@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"> 
}
于 2013-03-18T18:28:44.310 回答
0

用这个:

@{
    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> 
    }
}
于 2013-03-18T18:45:29.817 回答