asp.net mvc - DataFormatString for DateTime -


i'm trying apply format in datetime attribute not working. have this:

[datatype(datatype.date)] [displayformat(dataformatstring = "dd/mm/yyyy", applyformatineditmode = true)] public datetime datainscricao { get; set; } 

i've tried in many ways (changing dataformatstring) none of them working. i'm using datepicker date fields.

i tried apply format jquery:

$("#datainscricao").datepicker( {dateformat: 'dd-mm-yy'}); 

it works, format applied in textbox when try save date format lost. if enter date 12/01/2013, changes 01/01/0001. in gridview format different (mm-dd-yyyy) , mask of textbox working wrong.

i don't know make work. there can me issue?

thanks!

update

this method in controller returns entity edit.

public actionresult editar(int id) {     var agendamento = _repository.getsingle(a => a.id == id);     return view("criar", agendamento); } 

and view:

@model pncq2013.domain.entities.agendamentomanutencao @{     viewbag.title = pncq2013.domain.resources.itempatrimonio.itempatrimonio.titleagendamento + " :: pncq - programa nacional de controle de qualidade";     layout = "~/views/shared/_layout.cshtml"; }  <div class="section"> @using (ajax.beginform("salvar", "manutencaopreventiva", null, new ajaxoptions { httpmethod = "post", loadingelementid = "loading" }, new { @class = "formee", @id = "frmagendamentomanutencao", enctype = "multipart/form-data" })) {     @html.hiddenfor(m => m.id)     <div class="box">         <div class="title">             @pncq2013.domain.resources.itempatrimonio.itempatrimonio.titleagendamento         </div>         <div class="content nopadding">             <div class="grid-4-12">                 @html.labelfor(m => m.itempatrimonioid)                 @html.dropdownlistfor(m => m.itempatrimonioid, new selectlist(pncq2013.web.content.helpers.util.listaitempratrimonio().orderby(a => a.numeropatrimonio), "id", "numeropatrimonio"), resources.geral.selecione)                 @html.validationmessagefor(m => m.itempatrimonioid)             </div>             <div class="grid-4-12">                 @html.labelfor(m => m.datainscricao)                 @html.textboxfor(m => m.datainscricao, new { @class = "datepicker" })                 @html.validationmessagefor(m => m.datainscricao)             </div>             <div class="grid-4-12">                 @html.labelfor(m => m.frequenciamanutencaoid)                 @html.dropdownlistfor(m => m.frequenciamanutencaoid, pncq2013.web.content.helpers.htmlextensions.toselectlist(typeof(pncq2013.domain.enumerators.frequenciamanutencao), ""), resources.geral.selecione)                 @html.validationmessagefor(m => m.frequenciamanutencaoid)             </div>         </div>     </div> } 

try this,

[datatype(datatype.date)] [displayformat(dataformatstring = "{0:dd/mm/yyyy}", applyformatineditmode = true)] public datetime datainscricao { get; set; } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -