I have tried all of the solutions I could already find on stackoverlfow as well as starting again following instructions found here https://stick2basic.wordpress.com/2013/04/14/how-to-pass-model-from-view-to-controller-using-jquery/
Every time I trigger my ajax call it passes null to the controller
*Fixed spelling mistake, issue still occurs
Model
public class DateModel
{
public DateTime date { get; set; }
}
JavaScript
$(document).ready(function () {
$("#jqxdatetimeinput").jqxDateTimeInput({ width: '250px', height: '25px' });
$("#jqxbutton").jqxButton({ width: '150', height: '25' });
$("#jqxbutton").on('click', function () {
var dateSelected = $('#jqxdatetimeinput').jqxDateTimeInput('getDate');
alert(dateSelected);
var DateModel =
{
"date": dateSelected
};
$.ajax({
url: 'home/submitDate/',
data: JSON.stringify(DateModel),
type: 'POST',
contentType: 'application/json; charset=utf-8',
success: function (data) {
alert(data);
}
});
});
});
Controller
public class HomeController : Controller
{
public IActionResult Index()
{
DateModel selectionDate = new DateModel();
return View();
}
public JsonResult submitDate(DateModel selectionDate)
{
return Json(selectionDate.date);
}
}