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> €
}
@if(item.price_d.HasValue)开发者_如何学运维
<text>$
}
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>$
}
</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> €</text>
}
@if(item.price_d.HasValue) {
<text>$</text>
}
else {
@item.price
}
Your second code sample is also missing a </div>
精彩评论