开发者

Using if has value statement in razor view not working

I have a db table with 3 different {price (value> int)} parameters I would like in my view that in case one of them has value in it to display same html code I had tried something like this in my view (not working)

@if(item.price_e.HasValue )
  <text> &euro;
}

@if(item.price_d.HasValue)开发者_如何学运维
  <text>&#36;
}
else
  item.price

what the way to do it? My view

@foreach (var item in Model) {
  <div class="prod" >
    <div class="prodh">
      <h3> @item.destination
        @item.City
        @item.pkg_type
      </h3>
      @item.description
      //i have also tryed this Not working
      @if(item.price !=0) 
      {
        <text>bla
      }
      @if(item.price_d !=0)
      {
        <text>&#36;
      }
    </div>
  <div class="prodb">
    @item.date
    @item.company.company_id
    @item.destination</div>
  </div> 
}


You are missing some } and haven't closed the <text> with </text>

@if(item.price_e.HasValue ) {
  <text> &euro;</text>
}
@if(item.price_d.HasValue) {
  <text>&#36;</text>
} 
else {
  @item.price
}

Your second code sample is also missing a </div>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜