Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.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
Javascript 从datatable ASP.NET 5 MVC 6向控制器发送JSON的AJAX post出现问题_Javascript_Jquery_Json_Ajax_Datatables - Fatal编程技术网

Javascript 从datatable ASP.NET 5 MVC 6向控制器发送JSON的AJAX post出现问题

Javascript 从datatable ASP.NET 5 MVC 6向控制器发送JSON的AJAX post出现问题,javascript,jquery,json,ajax,datatables,Javascript,Jquery,Json,Ajax,Datatables,我在获取ajax调用以将JSON数据传递给控制器时遇到问题。我的应用程序使用ASP.NET5和MVC6,在本例中,我使用的是datatables JQuery网格。通过在我的视图中使用复选框,我试图选择多行数据,然后让用户只需单击一个按钮即可批准所有选定的行 function addData(data) { /*POST*/ $.ajax({ url: '/Expenses/ApproveMany',

我在获取ajax调用以将JSON数据传递给控制器时遇到问题。我的应用程序使用ASP.NET5和MVC6,在本例中,我使用的是datatables JQuery网格。通过在我的视图中使用复选框,我试图选择多行数据,然后让用户只需单击一个按钮即可批准所有选定的行

        function addData(data) {
            /*POST*/
            $.ajax({
                url: '/Expenses/ApproveMany',
                dataType: "json",
                type: "POST",
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify( data ),
                cache: false,                
                success: function (result) {
                    alert(result);
                },
                error: function (xhr) {
                    alert('error');
                }
            })
        }
我注意到我用javascript获得了正确的选定行,但是在AJAX传递数据之前,当我选择两行时,数据如下所示

Selected rows: 2
,1109,tester,3/9/2016,QOL,International Flights,Test email,484.00,Submitted,<a href="/Expenses/Review/1109">Review</a>
   [
      0: "",
      1: "1109",
      2: ""tester",",
      3: "3/9/2016",
      4: "QOL",
      5: "International Flights",
      6: "Test email",
      7: "484.00",
      8: "Submitted",
      9: "<a href="/Expenses/Review/1109">Review</a>",
      length: 10
   ]

,1111,tester,4/13/2016,QOL,Visa Stipend - Visas,total cost test 2,48.00,Submitted,<a href="/Expenses/Review/1111">Review</a>
   [
      0: "",
      1: "1111",
      2: "tester",
      3: "4/13/2016",
      4: "QOL",
      5: "Visa Stipend - Visas",
      6: "total cost test 2",
      7: "48.00",
      8: "Submitted",
      9: "<a href="/Expenses/Review/1111">Review</a>",
      length: 10
   ]
        function addData(data) {
            /*POST*/
            $.ajax({
                url: '/Expenses/ApproveMany',
                dataType: "json",
                type: "POST",
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify( data ),
                cache: false,                
                success: function (result) {
                    alert(result);
                },
                error: function (xhr) {
                    alert('error');
                }
            })
        }
视图模型

        function addData(data) {
            /*POST*/
            $.ajax({
                url: '/Expenses/ApproveMany',
                dataType: "json",
                type: "POST",
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify( data ),
                cache: false,                
                success: function (result) {
                    alert(result);
                },
                error: function (xhr) {
                    alert('error');
                }
            })
        }
public class ApproveVm
        public string check {get;set;}

        public int ExpenseId { get; set; }

        [Display(Name = "Requester")]
        public virtual string ApplicationUserid { get; set; }

        [DisplayFormat(DataFormatString = "{0:d}",
            ApplyFormatInEditMode = true)]
        [Display(Name = "Expense Date")]
        public DateTime ExpenseDate { get; set; }
        [Display(Name = "Expense Type")]
        public int? ExpenseTypeId { get; set; }

        [Display(Name = "Expense Code")]
        public int? ExpenseCodeId { get; set; }
        public string Description { get; set; }

        [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
        [Display(Name = "Total Cost")]
        public decimal TotalCost { get; set; }

        public string Status { get; set; }
        public string Review { get; set; }

}
控制器

        function addData(data) {
            /*POST*/
            $.ajax({
                url: '/Expenses/ApproveMany',
                dataType: "json",
                type: "POST",
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify( data ),
                cache: false,                
                success: function (result) {
                    alert(result);
                },
                error: function (xhr) {
                    alert('error');
                }
            })
        }
  [HttpPost]


    public IActionResult ApproveMany([FromBody] IEnumerable<ApproveVm> model)
    {
    }
[HttpPost]
公共IActionResult ApproveMany([FromBody]IEnumerable模型)
{
}

您忘记了数据库表man:))视图使用的费用表只是一个标准的poco类,大约有25个字段。上面的视图仅提取这些字段的一个子集。还忘了提到我使用的entity framework 7并不是说它会有很大的不同。在进一步讨论之前,您必须知道,当您使用.data()方法获取表数据时,它会返回所选行数据的对象,因此它将包含一些元数据,而不仅仅是您期望的普通数据。请相应地修改您的数据访问逻辑。Hi Prakash,您能解释一下如何修改数据访问技术吗。是否有其他方式访问它?