javascript - Date Formats in MVC -


my view models , controllers seem save date time in different format. instance, in view in html text box, if had entered in 07/12/2015, have saved value if "december 7, 2015". using boostrap javascript datetime picker. (a side note: if entered in "dateformat" datetime picker, picker not work, , that's why commented out line)

is there way such can change saved format of html text box?

my view model: (part)

 <div class="form-group"> @html.label("actual completion date", htmlattributes: new { @class = "control-label col-md-2" })             <div class="col-md-10">                 @html.editorfor(model => model.actual_completion_date, new { htmlattributes = new { @value = model.actual_completion_date, @class = "form-control" } })             </div>         @html.validationmessagefor(model => model.actual_completion_date, "", new { @class = "text-danger" })     </div>          <div class="form-group">             <div class="col-md-offset-2 col-md-10">                 <input type="submit" value="save" class="btn btn-default" />             </div>         </div>      </div> }  @section scripts {     <script type="text/javascript">         $(function () {             $('#actual_completion_date').datetimepicker({                 //dateformat: "dd/mm/yyyy",                 defaultdate: '@model.actual_completion_date',                 format: 'l',                 showclose: true,                 showclear: true,                 toolbarplacement: 'top',             });              $('#actual_completion_date').datetimepicker({                 defaultdate: '@model.actual_completion_date',                 format: 'lt',                 showclose: true,                 showclear: true,                 toolbarplacement: 'top',                 stepping: 15,             });         });     </script> } 

my model (part):

    [datatype(datatype.date)]     [displayformat(dataformatstring = "{0:mm/dd/yyyy}", applyformatineditmode = true)]     public nullable<system.datetime> date_assigned { get; set; }      [datatype(datatype.date)]     [displayformat(dataformatstring = "{0:mm/dd/yyyy}", applyformatineditmode = true)]     public nullable<system.datetime> actual_completion_date { get; set; } 

any advice or pointers? many in advance.

how datetime parsed depends on current language posted values , values passed querystring.

values passed part of route parsed using invariant culture. check f12 tools or fiddler kind of request have.

if want change behaviour change curent culture thread (for posted values , querystrings) or register own midelbinder (for route values)


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -