c# - Different date format in same model -
hi doing project in mvc4 using c#
i have model
[displayformat(dataformatstring = "{0:ddd, d mmmm yyyy}")] public datetime eve_date { get; set; }
that take date sql database (date stored in db mm/dd/yy format time).my problem that, show date in 2 view pages, 1 page shows date
sun, 11 august 2013 (@html.displayfor(modelitem=>item.eve_date))
and page shows 8/11/2013 12:00:00 am(@model.eve_date).
in case of localhost shown 31-07-2013 pm 05:00:00(@model.eve_date). when published difference shown. can identify actual problem. want show date in pages format sun, 11 august 2013
1st page is
@model ienumerable<....models.eventdetails> <tbody> @foreach(var item in model) { <tr><td class="evname"><a href="~/event/eventdetails/@item.id">@html.displayfor(modelitem=>item.eve_na)</a></td> <td class="evdate">@html.displayfor(modelitem=>item.eve_date)</td> <td class="evplace">@@@html.displayfor(modelitem=>item.eve_place)</td> </tr> } </tbody>
2nd page is
@model p.....models.eventdetails <tbody> <tr><th>event</th><td>@model.eve_na</td><tr> <tr><th>date</th><td>@model.eve_date</td></tr> <tr><th>venue</th><td>@model.eve_place</td></tr> <tr><th>details</th><td><p>@model.eve_desc</p></td></tr> <tr><th colspan="2" style="color:#3b619b;">for more information, please contact</th></tr> <tr><th>contact person</th><td>@model.eve_contact</td></tr> <tr><th>email</th><td>@model.eve_email</td></tr> <tr><th>phone</th><td>@model.eve_phone</td></tr> </tbody>
i think @model.eve_date
uses default date format , displayfor
uses formatting specified in displayformat
attribute.
so should change second line @html.displayfor(modelitem=>item.eve_date)
well.
your system set show dates in ddd, d mmmm yyyy formatting. , server using default formatting. that's why it's same on localhost , different on server.
Comments
Post a Comment