剃刀 - 比较时间条件

时间:2015-06-17 17:48:53

标签: c# razor

我希望在下午5:00或之后显示元素。如何设置条件来执行此操作?

<div class="time">@Model.EventDateAndTime</div> <!-- outputs JUN 18 2015 9:00 PM -->

@if(@Model.EventDateAndTime > ??? ){
     <a href="#">My Link</a>
}

2 个答案:

答案 0 :(得分:4)

DateTime结构has an Hour property

@if(Model.EventDateAndTime.Hour >= 17){
    <a href="#">My Link</a>
}

答案 1 :(得分:0)

  @if(Model.OfferType == "TM Event" && DateTime.Parse(Model.EventDateAndTime).ToString("HH").AsInt() >= 17 ){
       <a href="https://www.sevenrooms.com/direct/reservation-request/musichalllv/table" data-fancybox-type="iframe" class="button upgrade" style="padding-top:25px;" data-fancybox-type="iframe" class="button table">VIP TABLE INQUIRY</a>
  }