Hey guys I am new to MVC, javascript, ajax, and C#. Fresh over from VB .Net. I am working with MVC 5 at the moment. I have a jQuery datepicker in a View and onSelect I have it doing a function in jQuery that gets the currentDate and uses ajax to send the post to the controller. The jscript gets the current date ( although my format doesn't work currently ), and sends the post, but the post is either sending null data, or the controller is not accepting it.
javascript Code:
<script type="text/javascript">
$(function () {
$('#datepicker').datepick({ onSelect: getDate, dateFormat: "yy-mm-dd" });
function getDate(date)
{
var currentDate = $("#datepicker").datepick("getDate");
$.ajax({
type: "post",
url: "SelectDay",
dataType: "json",
data: { theDate: currentDate }
})
}
});
</script>
c# Code:
// GET: /Timeclock/SelectDay
public ActionResult SelectDay(string theDate)
{
TimeclockViewModel tt = new TimeclockViewModel();
// stuff goes here
return View(tt);
}
lets get this MVC subforum going
Solved:
Always remember to fully put your /Ctrl/Actn
Leaving "SelectDay" would link to the right action in the controller, but not actually send the data to it.
I had to put "/Timeclock/SelectDay" to actually recieve the data.
Code:
$.ajax({
type: 'POST',
url: '/Timeclock/SelectDay',
traditional: true,
dataType: "json",
data: { theDate: currentDate }
})