将Javascript值分配给Model变量

时间:2015-05-21 10:27:34

标签: javascript asp.net-mvc

我想将大量数据从javascript传递给模型。我已经尝试过首先将它发送到数据,但它不能处理大数据,所以有没有办法从javascript设置模型值

我目前正在做的是

function SaveData() {

        var BatchNo = new Array();

        $("table#tbl1 tr").each(function (row, tr) {

            BatchNo[row]  = $(tr).find('td:eq(2)').text()

        });
        BatchNo.shift();

        $.ajax({
            url: "@Url.Action("SaveMedicineTable", "MedicinePurchase")",
            traditional : true,
            dataType: "json",
            data: {
                BatchNo: BatchNo,

            },
            success: function (result) {

                //Your success message
            },
            error: function (result) {
                //alert("Error" + result);
                //Your error message
            }
        });
    }

点击保存按钮时此功能将调用控制器,但是我的数据很大,所以我无法达到它。所以我需要一些不同的东西,我可以设置模型值或传递大量数据 下面是我的控制器代码。我从javascript传递到控制器

这个很多场
Function SaveMedicineTable(MedicineName() As String, BatchNo() As String, ExpiryDate() As String, Qty() As String, FreeQty() As String, PurRate() As String,
                               Mrp() As String, SellRate() As String, Unit() As String, Amount() As String, DiscPer() As String, DiscAmt() As String,
                               GrossAmt() As String, VatPer() As String, VatAmt() As String, AddVatPer() As String, AddVatAmt() As String, NetAmt() As String, MedicineID() As String,
                              SupplierID As String, ChallanNo As String, PurchaseDate As String, BillNo As String, BillDate As String, PayDate As String,
                              PayMode As String, ItemTotal As String, BankName As String, DocNo As String, AddLessAmt As String, AddLessRemarks As String, BillAmount As String,
                        BillRemarks As String, AcDate As String, chkEdit As String) As JsonResult
        Dim mpm As New MedicinePurchase
        mpm.HospitalID = Session("hospital_id")
        mpm.WorkingYear = 2014
        mpm.PurchaseType = 1
        mpm.SupplierID = SupplierID
        mpm.ChallanNo = ChallanNo
        mpm.PurchaseDate = PurchaseDate
        mpm.BillNo = BillNo
        mpm.BillDate = BillDate
        mpm.PayDate = PayDate
        mpm.PayMode = PayMode
        mpm.ItemTotal = ItemTotal
        mpm.BankName = BankName
        mpm.DocNo = DocNo
        mpm.AddLessAmt = AddLessAmt
        mpm.AddLessRemarks = AddLessRemarks
        mpm.BillAmount = BillAmount
        mpm.BillRemarks = BillRemarks
        mpm.AcDate = AcDate
        mpm.ChkEdit = chkEdit
        mpm.AddMedicinePurchase(MedicineName, BatchNo, ExpiryDate, Qty, FreeQty, PurRate,
                                    Mrp, SellRate, Unit, Amount, DiscPer, DiscAmt,
                                    GrossAmt, VatPer, VatAmt, AddVatPer, AddVatAmt, NetAmt, MedicineID)

        Return Json("Success", JsonRequestBehavior.AllowGet)
    End Function

这是我得到的另一个错误

Failed to load resource: the server responded with a status of 404 (Not Found): http://localhost:54248/MedicinePurchase/SaveMedicineTable?{%22BatchNo%22:[%22167%22,%224623005%22,%22P1210022%22,%220021%22,%22ra9002%22,%220911055%22,%221011248%22,%22B1005%22,%22247%22,%22522005%22,%22296020%22,%22T-70020%22,%221836%22,%22113%22,%22D201C133%22,%22904672%22,%2210A2911%22,%22AD82695%22,%22LBB40019%22,%22a90149%22,%2210B1512%22,%222530%22,%22LW152036AS0%22,%22DE61206%22,%22H009%22,%22E005%22,%22727%22,%221572%22,%22ZC261003%22,%221713137%22,%22AP012%22,%22A81307%22,%22D90118%22,%22FD6L12L%22,%22282404%22,%22NL102%22,%226064011%22,%22BA11%22,%22ANT101%22,%22BK49%22,%22C00805%22,%22F40002%22,%227054046%22,%227024025%22,%227014029%22,%2247612%22,%224785001%22,%224804002%22,%22A402%22,%22BAE29%22,%22ROE405%22,%22S026%22,%22E048%22,%22ELE402%22,%22R005%22,%22FZD412%22,%22C006%22,%22B004%22],%22ExpiryDate%22:[%2230/11/2016%22,%2231/10/2015%22,%2230/09/2014%22,%2231/12/2009%22,%2230/06/2010%22,%2230/10/2014%22,%2231/10/2015%22,%2230/06/2016%22,%2231/12/2007%22,%2231/10/2007%22,%2230/11/2010%22,%2231/07/2008%22,%2231/08/2009%22,%2228/02/2007%22,%2231/08/2015%22,%2231/03/2013%22,%2231/12/2014%22,%2230/11/2011%22,%2231/12/2016%22,%2230/12/2011%22,%2230/12/2014%22,%2231/05/2013%22,%2231/10/2015%22,%2230/06/2008%22,%2230/11/2010%22,%2230/11/2005%22,%2231/03/2009%22,%2230/09/2009%22,%2231/01/2008%22,%2230/05/2013%22,%2230/11/2014%22,%2230/11/2010%22,%2230/12/2010%22,%2231/08/2009%22,%2230/11/2006%22,%2231/01/2010%22,%2231/07/2006%22,%2231/08/2007%22,%2228/02/2007%22,%2231/12/2006%22,%2230/06/2006%22,%2231/12/2007%22,%2230/11/2007%22,%2230/11/2007%22,%2230/11/2007%22,%2230/11/2007%22,%2231/01/2008%22,%2230/11/2007%22,%2231/08/2007%22,%2231/01/2007%22,%2230/11/2006%22,%2231/08/2006%22,%2231/10/2006%22,%2230/09/2006%22,%2230/11/2006%22,%2231/10/2006%22,%2230/09/2006%22,%2231/12/2007%22],%22Qty%22:[%2211%22,%22100%22,%2220%22,%2210%22,%22120%22,%222400%22,%221200%22,%2212%22,%22120%22,%22300%22,%22100%22,%224%22,%22220%22,%2250%22,%2230%22,%222%22,%223600%22,%22100%22,%22120%22,%223%22,%226000%22,%221%22,%22500%22,%221%22,%22200%22,%225%22,%2250%22,%22100%22,%2250%22,%2210%22,%22100%22,%223%22,%22100%22,%2250%22,%2210%22,%22250%22,%2230%22,%223%22,%2250%22,%2250%22,%222%22,%2210%22,%2230%22,%2250%22,%2250%22,%2230%22,%2230%22,%2230%22,%222%22,%2250%22,%225%22,%2210%22,%222%22,%223%22,%225%22,%2220%22,%225%22,%225%22],%22FreeQty%22:[%220%22,%220%22,%226%22,%223%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%2230%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%2220%22,%222%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%2210%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22],%22PurRate%22:[%2269.57%22,%227.47%22,%2234.51%22,%2240.39%22,%224.93%22,%223.55%22,%223.55%22,%22100%22,%220.84%22,%221.02%22,%226.76%22,%22138.04%22,%223.23%22,%223.57%22,%2211.01%22,%22150%22,%221.85%22,%223.71%22,%224.8%22,%2212.75%22,%221.7%22,%2211%22,%225.33%22,%22158.39%22,%220.74%22,%229.68%22,%221.75%22,%2223.21%22,%224.79%22,%2218%22,%228.3%22,%2226.85%22,%221.14%22,%229.48%22,%2210.54%22,%220.41%22,%226.96%22,%2224.16%22,%223.42%22,%223.12%22,%2238.64%22,%2221.99%22,%222.02%22,%223.74%22,%226.29%22,%222.93%22,%222.14%22,%220.91%22,%2274.34%22,%225.19%22,%2230.4%22,%2229.38%22,%2262.71%22,%22104.22%22,%2220.76%22,%2224.09%22,%2254.09%22,%2238.55%22],%22Mrp%22:[%22100%22,%2210.5%22,%2244.85%22,%2251.75%22,%226.17%22,%2212.25%22,%2212.25%22,%22135%22,%220.95%22,%221.25%22,%228.45%22,%22170%22,%224.24%22,%224.05%22,%2213.51%22,%22210%22,%228.25%22,%224.8%22,%226.3%22,%2215.86%22,%226.9%22,%2213.85%22,%226.8%22,%22209%22,%220.95%22,%2211%22,%222%22,%2230.46%22,%225.76%22,%2225.7%22,%2252.5%22,%2235%22,%221.5%22,%2211.25%22,%2211.7%22,%220.5%22,%228%22,%2227.5%22,%223.9%22,%223.54%22,%2243.86%22,%2225%22,%222.36%22,%224.27%22,%227.3%22,%223.33%22,%222.38%22,%221.08%22,%2286%22,%225.9%22,%2235%22,%2231.9%22,%2269.05%22,%22115%22,%2222.82%22,%2228%22,%2262.5%22,%2245%22],%22SellRate%22:[%22100%22,%2210.5%22,%2244.85%22,%2251.75%22,%226.17%22,%2212.25%22,%2212.25%22,%22135%22,%220.988%22,%221.3%22,%228.787999999999998%22,%22176.8%22,%224.24%22,%224.212%22,%2213.51%22,%22210%22,%228.25%22,%224.8%22,%226.3%22,%2215.86%22,%226.9%22,%2213.85%22,%226.8%22,%22217.36%22,%220.95%22,%2211.44%22,%222.08%22,%2230.46%22,%225.9904%22,%2225.7%22,%2252.5%22,%2235%22,%221.5%22,%2211.7%22,%2212.168%22,%220.52%22,%228.32%22,%2228.6%22,%224.056%22,%223.6816%22,%2245.614399999999996%22,%2226%22,%222.4543999999999997%22,%224.440799999999999%22,%227.592%22,%223.4632%22,%222.4752%22,%221.1232%22,%2289.44%22,%226.136%22,%2236.4%22,%2233.176%22,%2271.812%22,%22119.6%22,%2223.7328%22,%2229.12%22,%2265%22,%2246.8%22],%22Unit%22:[%22FACE%20WASH%22,%22CAP%22,%22INJ%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Tab%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22TAB%22,%22Tab%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Tab%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Tab%22,%22Tab%22,%22Tab%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22,%22Pcs%22],%22Amount%22:[%22765.27%22,%22747%22,%22690.2%22,%22403.9%22,%22591.6%22,%228520%22,%224260%22,%221200%22,%22100.8%22,%22306%22,%22676%22,%22552.16%22,%22710.6%22,%22178.5%22,%22330.3%22,%22300%22,%226660%22,%22371%22,%22576%22,%2238.25%22,%2210200%22,%2211%22,%222665%22,%22158.39%22,%22148%22,%2248.4%22,%2287.5%22,%222321%22,%22239.5%22,%22180%22,%22830%22,%2280.55%22,%22114%22,%22474%22,%22105.4%22,%22102.5%22,%22208.8%22,%2272.48%22,%22171%22,%22156%22,%2277.28%22,%22219.9%22,%2260.6%22,%22187%22,%22314.5%22,%2287.9%22,%2264.2%22,%2227.3%22,%22148.68%22,%22259.5%22,%22152%22,%22293.8%22,%22125.42%22,%22312.66%22,%22103.8%22,%22481.8%22,%22270.45%22,%22192.75%22],%22DiscPer%22:[%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22],%22DiscAmt%22:[%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22],%22GrossAmt%22:[%22765.27%22,%22747%22,%22690.2%22,%22403.9%22,%22591.6%22,%228520%22,%224260%22,%221200%22,%22100.8%22,%22306%22,%22676%22,%22552.16%22,%22710.6%22,%22178.5%22,%22330.3%22,%22300%22,%226660%22,%22371%22,%22576%22,%2238.25%22,%2210200%22,%2211%22,%222665%22,%22158.39%22,%22148%22,%2248.4%22,%2287.5%22,%222321%22,%22239.5%22,%22180%22,%22830%22,%2280.55%22,%22114%22,%22474%22,%22105.4%22,%22102.5%22,%22208.8%22,%2272.48%22,%22171%22,%22156%22,%2277.28%22,%22219.9%22,%2260.6%22,%22187%22,%22314.5%22,%2287.9%22,%2264.2%22,%2227.3%22,%22148.68%22,%22259.5%22,%22152%22,%22293.8%22,%22125.42%22,%22312.66%22,%22103.8%22,%22481.8%22,%22270.45%22,%22192.75%22],%22VatPer%22:[%2212.5%22,%2212.5%22,%224%22,%224%22,%224%22,%224%22,%224%22,%224%22,%220%22,%220%22,%224%22,%2212.5%22,%224%22,%220%22,%224%22,%224%22,%224%22,%224%22,%224%22,%224%22,%224%22,%224%22,%224%22,%2212.5%22,%224%22,%220%22,%220%22,%224%22,%224%22,%224%22,%224%22,%224%22,%224%22,%224%22,%220%22,%224%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22],%22VatAmt%22:[%2295.66%22,%2293.38%22,%2227.61%22,%2216.156%22,%2223.664%22,%22340.8%22,%22170.4%22,%2248%22,%220%22,%2212.24%22,%2227.04%22,%2269.02%22,%2228.424%22,%220%22,%2213.21%22,%2212%22,%22266.4%22,%2214.84%22,%2223.04%22,%221.53%22,%22408%22,%220.44%22,%22106.6%22,%2219.799%22,%225.92%22,%220%22,%220%22,%2292.84%22,%229.58%22,%227.2%22,%2233.2%22,%223.222%22,%224.56%22,%2218.96%22,%220%22,%224.1%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22],%22AddVatPer%22:[%222.5%22,%222.5%22,%221%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%221%22,%220%22,%220%22,%220%22,%221%22,%220%22,%220%22,%220%22,%221%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22],%22AddVatAmt%22:[%2219.13%22,%2218.68%22,%226.9%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%223.3%22,%220%22,%220%22,%220%22,%225.76%22,%220%22,%220%22,%220%22,%2226.65%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22,%220%22],%22NetAmt%22:[%22880.06%22,%22859.06%22,%22724.71%22,%22420.056%22,%22615.264%22,%228860.8%22,%224430.4%22,%221248%22,%22100.8%22,%22318.24%22,%22703.04%22,%22621.18%22,%22739.024%22,%22178.5%22,%22346.81%22,%22312%22,%226926.4%22,%22385.84%22,%22604.8%22,%2239.78%22,%2210608%22,%2211.44%22,%222798.25%22,%22178.189%22,%22153.92%22,%2248.4%22,%2287.5%22,%222413.84%22,%22249.08%22,%22187.2%22,%22863.2%22,%2283.77199999999999%22,%22118.56%22,%22492.96%22,%22105.4%22,%22106.6%22,%22208.8%22,%2272.48%22,%22171%22,%22156%22,%2277.28%22,%22219.9%22,%2260.6%22,%22187%22,%22314.5%22,%2287.9%22,%2264.2%22,%2227.3%22,%22148.68%22,%22259.5%22,%22152%22,%22293.8%22,%22125.42%22,%22312.66%22,%22103.8%22,%22481.8%22,%22270.45%22,%22192.75%22],%22MedicineID%22:[%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22,%22%22],%22SupplierID%22:%22%22,%22ChallanNo%22:%2211012%22,%22PurchaseDate%22:%2201/04/2014%22,%22BillNo%22:%2211012%22,%22BillDate%22:%2201/04/2014%22,%22PayDate%22:%2214/05/2014%22,%22PayMode%22:%22Cheque%22,%22ItemTotal%22:%222343.92%22,%22BankName%22:%22BOB%22,%22DocNo%22:%22521669%22,%22AddLessAmt%22:%220.08%22,%22AddLessRemarks%22:%22%22,%22BillAmount%22:%222344%22,%22BillRemarks%22:%22%22,%22AcDate%22:%22%22,%22chkEdit%22:%22Yes%22}

1 个答案:

答案 0 :(得分:0)

我希望这个答案会对你有所帮助。使用ajax post和object方法,您可以将大值传递给模型。在示例中,我传递了10个值。 5个字符串数组和5个字符串变量

JQuery AJAX

function SaveDetails() {
    var obj = {
        arr1: ["1", "1", "1"],
        arr2: ["2", "2", "2"],
        arr3: ["3", "3", "3"],
        arr4: ["4", "4", "4"],
        arr5: ["5", "5", "5"],
        str1: "String 1",
        str2: "String 2",
        str3: "String 3",
        str4: "String 4",
        str5: "String 5"
    };

    $.ajax({
        url: '/Home/SaveTable',
        contentType: 'application/json; charset=utf-8',
        type: 'POST',
        data: JSON.stringify(obj),
        cache: false,
    });
}

<强>控制器

    public void SaveTable(List<String> arr1, List<String> arr2, List<String> arr3, List<String> arr5, string str1, string str2, string str3, string str4, string str5)
    {
      // Do your code
    }