MVC5从控制器到Ajax函数获取数据列表C#

时间:2018-09-02 11:18:50

标签: asp.net-mvc-5 asp.net-ajax

我正在将数据列表从控制器到ajax函数再到datatable.all都工作良好,但我的问题是,我想将list属性之一获取到文本框,将其他值获取到datatable列。例如: list = TotalAMount,PAidAmount,RemAmount 和数据表 总金额| PaidAMount |重新安装| --------- ?? 20 | 4 | 16 |

所以这很好用,但我想将TotalAmount值添加到某些文本框,例如textbox = 20。 我的JS函数== >> ` 函数AddGetHistoryView(SupplierID){

            $('#HistoryModal').modal('show');

            Datatabless = $("#HistoryTable").DataTable({
                "autoWidth": false,


                "ajax": {
                    "type": "GET",

                    "url": "@Url.Action("getHistoryData", "Supplier")/" + SupplierID,
                    "datatype": "JSON",

                    data: {
                        "Amount": $("#TotalAmount").val()


                    },
                    data: { SupplierID: SupplierID },






                },


                "columns": [

                    {
                        "data": "DetailID",
                        "visible": false,

                    },
                    {
                        "data": "TotalAmount",

                        "width": "5%",
                    },

                    {
                        "data": "PaidAmount",
                        "width": "5%",
                    },
                    {
                        "data": "RemAmount",
                        "width": "5%",
                    },
                    {
                        "data": "PaidDate",
                        "width": "5%",

                    },
                    {
                        "data": "PaymentType",
                        "width": "5%",
                    },

                    {


                        "data": "DetailID", "render": function (data) {
                            return "<a class='btn btn-success' onclick=EditRow(" + data + ") style='margin-left:12px'><i class='glyphicon glyphicon-edit'>&nbsp;Update</i><a/>,<a class='btn btn-danger' onclick=deleteRow(" + data + ") style='margin-left:12px'><i class='glyphicon glyphicon-trash'>&nbsp;Delete</i> <a/>";

                        },

                        "width": "40%",
                        "orderable": false,

                        "pagingType": "full_numbers",
                        "paging": true,


                    },



                ],





            });




        }

` 控制器方法==>

 public ActionResult getHistoryData(int SupplierID)
    {
        ob.Configuration.ProxyCreationEnabled = false;

        var data = ob.Table_Supplier.Join(ob.Table_SupplierDetails, sup => sup.SupplierID, det => det.SupplierID, (sup, det) => new
        {
            DetailID=det.DetailID,
            SupplierID = sup.SupplierID,
            TotalAmount = det.TotalAmount,
            RemAmount = det.RemAmount,
            PaidAmount = det.PaidAmount,
            PaidDate = det.PaidDate,
            PaymentType = det.PaymentType,
            Amount = sup.Amount


        }).Where(x=>x.SupplierID==SupplierID).ToList();


        return Json(new { data = data }, JsonRequestBehavior.AllowGet);
    }

0 个答案:

没有答案