2014-06-13 4 views
0

임금이 만료 된 행이나 만료일이 30 일인 행을 강조 표시하려고합니다. 내가 이것을 빌드하면 ... does not contain Definition for the ".Days"이라고합니다. 이 새로운 메신저"Days"에 대한 정의가 누락되었습니다

그렇게 그게 왜이 오류를 얻고있다 Days의 정의를 포함하지 않는 Nullable<TimeSpan> 객체를 반환합니다 PaidDate으로

@foreach (var item in Model) 
{ 
    int daysLeft = (item.MembershipType.PaidDate - DateTime.Today).Days; 

    string style = daysLeft <= 30 ? "background-color:Red" : null; 

    <tr style="@style"> 

     <td> 

      @Html.DisplayFor(modelItem => item.SupplierName) 

     </td> 

     <td> 

      @Html.DisplayFor(modelItem => item.MembershipType.PaidDate) 

     </td> 

     <td> 
      @Html.ActionLink("Edit", "Edit", new { id = item.Id }) | 
      @Html.ActionLink("Details", "Details", new { id = item.Id }) | 
      @Html.ActionLink("Delete", "Delete", new { id = item.Id }) 
     </td> 
    </tr> 
} 
+0

'PaidDate'의 유형은 무엇입니까? –

+0

PaidDate의 유형은 DateTime입니다 – anfield8

+0

정확히 무엇을 찾고 계십니까? – MarmiK

답변

0

nullable DateTimeDateTime?입니다 도와주세요, 당신이 있는지 확인해야합니다

if(item.MembershipType.PaidDate.HasValue) 
{ 
DateTime PaidDate = (DateTime)item.MembershipType.PaidDate; 
int daysLeft = (PaidDate - DateTime.Today).Days; 
} 

하거나에서 같은 줄에 전송할 수 있습니다 : null가 아닌 다음 DateTime에 캐스팅~ TimeSpan :

int daysLeft = ((TimeSpan)(item.MembershipType.PaidDate - DateTime.Today)).Days; 
+0

감사합니다. – anfield8

관련 문제