我正在努力通过ajax将数据传递给控制器

我正在努力通过ajax将数据传递给控制器

本文介绍了我正在努力通过ajax将数据传递给控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Trying to hit "DeleteJobQuote" controller through Ajax but no luck. Please guide me if anyone has any idea about it. The code seems OK but not able to do so. I am writing this code to delete a particular record from database.




Controller

What I have tried:

<pre><pre> [HttpPost]
        public JsonResult DeleteJobQuote(int jobQuoteid)
        {
            using (var db = new KeysEntities())
            {
                var delJob = db.JobQuote.FirstOrDefault(x => x.Id == jobQuoteid);
                if (delJob != null)
                {
                    delJob.Status = "Delete";
                    db.SaveChanges();
                    return Json(new { success = true, Message = "JobQuote SuccessFully Deleted!" });
                }
                else
                {
                    return Json(new { success = false, Message = "Delete UnSuccessFul " });
                }

            }

        }






















And JavaScript and Knockout


self.deleteJobQuote = function (jobQuote) {
        debugger;
         $.ajax({
         url: '/Companies/Manage/DeleteJobQuote',
            type: 'POST',
            dataType: 'json',
            data: JSON.Stringify({ jobQuoteid: 1028 }),
            //data: JSON.Stringify(jobQuote),
            contentType: 'application/json',
            success: function (result) {
                if (result.success) {
                     $('#jobQuoteDeleteModal').modal('show');
                  }
                else {
                    alert("You can not delete this record !!");
                     }
            }
        });
    };

推荐答案



public JsonResult DeleteJobQuote(string jobQuoteid) 
{
//then parse to int or other datatypes
}


这篇关于我正在努力通过ajax将数据传递给控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 00:40