To jest moja klasa:
public partial class Post
{
public Post()
{
this.PostImages = new HashSet<PostImage>();
this.PostMappings = new HashSet<PostMapping>();
}
public int ID { get; set; }
public string Title { get; set; }
public string TitleMenu { get; set; }
public string Preview { get; set; }
public string Content { get; set; }
public Nullable<int> Display { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> DateAdded { get; set; }
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> DateHide { get; set; }
public Nullable<int> PozitionMenu { get; set; }
public string Username { get; set; }
public virtual ICollection<PostImage> PostImages { get; set; }
public virtual ICollection<PostMapping> PostMappings { get; set; }
}
Chcę zaktualizować kolumnę DateHide.
@Html.TextBoxFor(model => model.DateHide, new { @class = "jquery_datepicker", @Value = (!Model.DateHide.HasValue ? "" : Model.DateHide.Value.ToString("dd/MM/yyyy"))})
$(".jquery_datepicker").datepicker({ dateFormat: "dd/mm/yy" });
Dodałem w web.config:
<globalization culture="en-US" />
I nadal pojawia się błąd:
Wartość „20/02/2014” nie jest ważna dla DateHide.
Odpowiedzi:
0 dla odpowiedzi № 1zastąpić
$(".jquery_datepicker").datepicker({ dateFormat: "dd/mm/yy" });
przez
$(".jquery_datepicker").datepicker({ dateFormat: "mm/dd/yy" });
Spowoduje to przekazanie do modelu daty w formacie „02/20/2014”.
0 dla odpowiedzi nr 2
Wymieniłem
@Html.TextBoxFor(model => model.DateHide, new { @class = "jquery_datepicker", @Value = (!Model.DateHide.HasValue ? "" : Model.DateHide.Value.ToString("dd/MM/yyyy"))})
z
<span class="jquery_datepicker"> @Html.EditorFor(model => model.DateHide, new { @class = "jquery_datepicker", @Value =Model.DateHide, displayMode })</span>
i
$(".jquery_datepicker").datepicker({ dateFormat: "dd/mm/yy" });
z
$(".jquery_datepicker input").datepicker({ dateFormat: "dd/mm/yy" });
Teraz działa! Ale nie wiem dlaczego. Jaka jest różnica między EditorFor i Pole tekstowe?