I am working on an asp.net mvc-4 web application. and i have the following fields:-
<div>
@Html.TextBoxFor(model => model.LiveDate, new { @class = "datepicker", @Value = (Model != null && Model.LiveDate.HasValue) ? Model.LiveDate.Value.ToString("dd/MM/yyyy") : string.Empty })
@Html.ValidationMessageFor(model => model.LiveDate)
</div>
<div>
@Html.TextBoxFor(model => model.EndDate, new { @class = "datepicker", disabled = "disabled",@Value = (Model != null && Model.EndDate.HasValue) ? Model.EndDate.Value.ToString("dd/MM/yyyy") : string.Empty })
@Html.ValidationMessageFor(model => model.EndDate)
</div>
<div>
@Html.EditorFor(model => model.ContractLength)
@Html.ValidationMessageFor(model => model.ContractLength)
</div>
now i defined the following jquery which should send the LiveDate & ContractLength to an action method to set the EndDate:-
$("#LiveDate, #ContractLength").change(function () {
$.getJSON("@Url.Content("~/Order/CalculateDate")", { date: $("#LiveDate").val(), month: $("#ContractLength").val() },
function (Data) {
$("#EndDate").val(Data.Name);
});
});
and here is the realted action method which will do the calculationspublic
public ActionResult CalculateDate(string date, int? month)
{
if (!String.IsNullOrEmpty(date) && month.HasValue)
{
DateTime d = DateTime.ParseExact(date, "dd/MM/yyyy", CultureInfo.InvariantCulture);
var Data = new { Name = d.AddMonths(month.Value) };
return Json(Data, JsonRequestBehavior.AllowGet);
}
return Json(new { Name=string.Empty}, JsonRequestBehavior.AllowGet);
}
now i tried this:-
- the livedate =
31/05/2016
- contract length in month=
7
- the action method return the following
31/12/2016 00:00:00
but inside the EndDate i got this value/Date(1483142400000)/
instead if"31/12/2016"
.. so can anyone advice accordingly ?