Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 通过$ajax将数据从视图发送到控制器时出错_Jquery_Ajax_Post - Fatal编程技术网

Jquery 通过$ajax将数据从视图发送到控制器时出错

Jquery 通过$ajax将数据从视图发送到控制器时出错,jquery,ajax,post,Jquery,Ajax,Post,我通过jQueryAjax调用将数据从视图发送到控制器,但是在这个给出错误对话框中,我不知道错误到底是什么。这是我的代码。 请帮帮我。我试过有评论的alernative,也试过这个 代码: 他们都没有工作 预订模式: public class Booking { public string reservationId { get; set; } public string startDate { get; set; } [Required(Erro

我通过jQueryAjax调用将数据从视图发送到控制器,但是在这个给出错误对话框中,我不知道错误到底是什么。这是我的代码。 请帮帮我。我试过有评论的alernative,也试过这个

代码:

他们都没有工作

预订模式:

     public class Booking
      {

    public string reservationId { get; set; }
    public string startDate { get; set; }
    [Required(ErrorMessage = "Please select Start date")]
    public string endDate { get; set; }
    [Required(ErrorMessage="Please select end date")]
    public string startHour { get; set; }
    [Required(ErrorMessage="Please select Start time")]
    public string endHour { get; set; }
    [Required(ErrorMessage="Please select end time")]
    public string amount { get; set; }
    public string vehicleId { get; set; }
    public string spaceId { get; set; }
    public string userId { get; set; }
    }
视图:


在警报框中出现了错误:不知道错误您的预订类定义是什么?请看。我已经计算了我的代码数据:{'startValue':startValue,'endValue':endValue},数据:{startValue:startValue,endValue:endValue},看起来不像预订类。另外,为什么后面有逗号?
     public class Booking
      {

    public string reservationId { get; set; }
    public string startDate { get; set; }
    [Required(ErrorMessage = "Please select Start date")]
    public string endDate { get; set; }
    [Required(ErrorMessage="Please select end date")]
    public string startHour { get; set; }
    [Required(ErrorMessage="Please select Start time")]
    public string endHour { get; set; }
    [Required(ErrorMessage="Please select end time")]
    public string amount { get; set; }
    public string vehicleId { get; set; }
    public string spaceId { get; set; }
    public string userId { get; set; }
    }
       <script type="text/JavaScript">
        function sendVales() {
        var startValue = $('#startDate').val();
        var endValue = $('#endDate').val();
        alert(startValue + "" + endValue);

        var dataRequested = { startDate: startValue, endDate: endValue };
        $.ajax({

            type: "POST",
            contentType: "application/json;charset=utf-8",
            url: '@Url.Action("makeReservation", "Booking")',
          //  data:{startValue : startValue,endValue:endValue },
            data: JSON.stringify(dataRequested),
                dataType: "json",
                success: function (data) {
                    alert("Success, sent data to controller");
                },
                error: function (data) {
                    alert("Error: " + data.responseText);
                }
        });
    }

</script>
       [HttpPost]

        public JsonResult makeReservation(Booking bookModel)
        {    bool success = false;
        try
        {
            success = bookingObj.addBooking(userName, bookModel);
            if (success)
            {
                ModelState.AddModelError("", "Space has been booked.");
            }
            else
            {
                ModelState.AddModelError("", "Space can be reserved.Correct the errors and try aggain");
            }

        }
        catch (Exception ex)
        {
            ModelState.AddModelError("", ex);
        }
             return Json(new { success }, JsonRequestBehavior.AllowGet);
         }