formatlar model classında field ın hemen üzerinde olacak, (aşağıdaki gibi). bu sayede sayfalarda displayfor ederken birşey yapmak gerekmez.
model ->
public Nullable<int> EmployeeID { get; set; }
[System.ComponentModel.DataAnnotations.DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
public Nullable<System.DateTime> OrderDate { get; set; }
[System.ComponentModel.DataAnnotations.DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
public Nullable<System.DateTime> RequiredDate { get; set; }
[System.ComponentModel.DataAnnotations.DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
public Nullable<System.DateTime> ShippedDate { get; set; }
view ->
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.OrderDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.RequiredDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.ShippedDate)
</td>
...
model ->
public Nullable<int> EmployeeID { get; set; }
[System.ComponentModel.DataAnnotations.DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
public Nullable<System.DateTime> OrderDate { get; set; }
[System.ComponentModel.DataAnnotations.DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
public Nullable<System.DateTime> RequiredDate { get; set; }
[System.ComponentModel.DataAnnotations.DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
public Nullable<System.DateTime> ShippedDate { get; set; }
view ->
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.OrderDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.RequiredDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.ShippedDate)
</td>
...
Yorumlar
Yorum Gönder