Skip to content

Instantly share code, notes, and snippets.

@TheDarkTrumpet
Created March 23, 2015 20:02
Show Gist options
  • Select an option

  • Save TheDarkTrumpet/9255ec35f3394ab14449 to your computer and use it in GitHub Desktop.

Select an option

Save TheDarkTrumpet/9255ec35f3394ab14449 to your computer and use it in GitHub Desktop.
Please use DisplayFor, especially on dates
///////// In model..... //////////////////
[DisplayName("Warranty Expiration Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
public DateTime? WarrantyExpiryDateTime { get; set; }
///////// In View..... /////////////////
@Html.EditorFor(model => model.WarrantyExpiryDateTime, new {maxlength = 10, @class = "datePicker"})
//////// In a view that iterates (iEnumberable) ////////////
@foreach (ComputerAsset item in Model)
{
<tr>
.....
<td>@Html.DisplayFor(i => item.DateAcquired)</td>
.....
</tr>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment