Reputation: 18068
In my Person
model I got birthdate property:
[DisplayName("Date of Birth")]
[DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
[DataType(DataType.Date)]
public DateTime BirthDate { get; set; }
In Edit view I got birth date input field displayed:
<div class="form-group">
@Html.LabelFor(model => model.BirthDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.BirthDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.BirthDate, "", new { @class = "text-danger" })
</div>
</div>
On localhost it produces HTML:
<input class="form-control text-box single-line valid" data-val="true" data-val-date="The field Date of Birth must be a date." data-val-required="Pole Date of Birth jest wymagane." id="BirthDate" name="BirthDate" type="date" value="2014-10-02">
and the value of the field is displayed in the browser after the page is loaded:
I published my application but the produced HTML is slightly different. It doesn't contain the word valid
and the value
format is different:"2/5/2015"
instead of "2014-10-02"
.
<input class="form-control text-box single-line" data-val="true" data-val-date="The field Date of Birth must be a date." data-val-required="The Date of Birth field is required." id="BirthDate" name="BirthDate" type="date" value="2/5/2015">
This causes that the date is not displayed in the input field until I set it by datepicker.
I want it to behave the same way as locally deployed app.
I am based in Poland, The application was deployed to the myasp.net servers which I bet are in Anglo-Saxon country with different date format. Is this might be a problem?
Upvotes: 0
Views: 121
Reputation: 8359
I think you should set your culture in your webProject manually. By this the culture settings on the deployment server won't be applied.
web.config
<globalization uiCulture="pl" culture="pl-PL" />
see MSDN - How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization
If you are concerned about globalization of your project you can change the culture of a single page too
yourPage.aspx
<%@ Page UICulture="pl" Culture="pl-PL" %>
If you don't won't this either you can set a custom dataFormatString rather than pointing to a standard format string which applies to a cultureSetting.
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime BirthDate { get; set; }
Upvotes: 1