asp.net mvc - MVC ajax form submission returns default date of DateTime property -
i using below ajax form select , post date ranges.
view model:
public class viewformsubmissionsvm { public string formname { get; set; } public guid formid { get; set; } [display(name="from:")] public datetime { get; set; } [display(name = "to:")] public datetime { get; set; } }
razor/html:
@model viewformsubmissionsvm @using (ajax.beginform("viewformsubmissions", "form", new ajaxoptions { httpmethod = "post", onsuccess = "ongetsubmissionsuccess", onfailure = "ongetsubmissionerror" }, new { @class = "form-horizontal" })) { @html.antiforgerytoken() @html.hiddenfor(x => x.formid) <div class="row col-md-12"> <div class="pull-right"> <label class="control-label col-md-3">@html.displaynamefor(x => x.from)</label> @html.textboxfor(x => x.from, "{0:mm/dd/yyyy}", new { @class = "form-control col-md-3", @data_picker = "date-picker" }) <label class="col-md-3">@html.displaynamefor(x => x.to)</label> @html.textboxfor(x => x.to, "{0:mm/dd/yyyy}", new { @class = "form-control col-md-3", @data_picker = "date-picker" }) <input type="submit" class="btn btn-primary" value="search" /> </div> </div> }
jquery date picker:
$(document).ready(function () { $('*[data-picker="date-picker"]').datepicker(); });
this issue while submitting form, "from" , "to" datetime properties, received default date values instead of selected.
am missing important!! have used these codes in different forms, never experienced before.
could 1 me out of one.
many thanks.
first of all, think should call overload:
using (ajax.beginform("viewformsubmissions", "form", null, new ajaxoptions{ httpmethod = "post", onsuccess = "ongetsubmissionsuccess", onfailure = "ongetsubmissionerror" }, new {@class = "form-horizontal" }))
with null 3rd parameter.
second, check datetime format. can find more info here: mvc datetime binding incorrect date format, asp.net mvc datetime culture issue when passing value controller or http://weblogs.asp.net/melvynharbour/mvc-modelbinder-and-localization.
Comments
Post a Comment