Ich habe diese Aussage in meiner Ansicht, dass wie folgt:wie ein Datum Zeitvariable in asp.net MVC-Format @ HTML.DisplayNameFor
<th>
@Html.DisplayNameFor(model => model.ReleaseDate)
</th>
alles, was ich bin versucht, Format des Release-Datum zu tun ist, so dass es im Format von MM/TT/JJJJ sein wird. Ich habe Ladungen durchsucht und bin nicht auf etwas gestoßen, das genau das ist, wonach ich suche. Jede Hilfe würde sehr geschätzt werden, ich bin relativ neu in der Codierung.
Hier ist mein Modell:
using System;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
namespace MvcMovie2.Models
{
public class Movie
{
public int ID { get; set; }
public string Title { get; set; }
public DateTime ReleaseDate { get; set; }
public string Genre { get; set; }
public string Rating { get; set; }
public decimal Price { get; set; }
}
public class MovieDBContext : DbContext
{
public DbSet<Movie> Movies { get; set; }
}
public class DummyModel : Movie
{
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime ReleaseDate { get; set; }
}
}
und hier ist meine Ansicht:
@model IEnumerable<MvcMovie2.Models.Movie>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Title)
</th>
<th>
@Html.DisplayFor(model => model.ReleaseDate)
</th>
<th>
@Html.DisplayNameFor(model => model.Genre)
</th>
<th>
@Html.DisplayNameFor(model => model.Rating)
</th>
<th>
@Html.DisplayNameFor(model => model.Price)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReleaseDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Genre)
</td>
<td>
@Html.DisplayFor(modelItem => item.Rating)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</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>
}
</table>
Bitte teilen Sie Ihr Modell –
'DisplayNameFor()' gibt den Eigenschaftsnamen (oder das Ergebnis eines 'DisplayAttribute'. Hast du' @ Html.DisplayFor() '? –
@ Html.DisplayFor (Modell => Modell bedeuten. ReleaseDate) In der obigen Zeile muss das Datum in MM/TT/JJJJ formatiert werden –