I have in my view Datetime fied like these
@Html.EditorFor(m => m.StartDate)
<input type="button" id="pickDate" value="Send date" />
Jquery datepicker is implement and I’m using DateTime.cshtml inside shared folder like these
@model DateTime
@Html.TextBox("", Model.ToString("d|M|yyyy"),
new { @class = "date" })
$('#pickDate').click(function () {
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: '/Home/DateManipulation',
success: function (result) { alert('Success');},
error: function () { alert("error"); }
});
});
[HttpPost]
public JsonResult DateManipulation()
{
DateTime date = DateTime.ParseExact(Request.Params["MyDate"], "d|M|yyyy", CultureInfo.InvariantCulture);
var data = //process some other manipulation with data
return Json(data);
}
Question is: how to send date using above js script.
Retrieve value of the
StartDateinput field and pass it as adatato the ajax request.And on server side you can specify the corresponding parameter for action method: