Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67441

How to Display Record in Html after Saving in to MVC Model Input via Jquery

$
0
0

Actually I just want to display Max record in html front end by using jquery and moreover i have successfully saved the data in model here is my jquery code:

$("#btnSave").click(function () {

            //var itemcode;
            //var qty;
            var books = $('#CbTable');
            if (books.val() === '') {
                alert("Please select an Table from the list and then proceed!");
                $('#CbTable').focus();

                return false;
            }

            else {

                var a = [];
                $('#tablefinaldata').find('tbody').find('tr').each(function () {


                    //InvNo: $('#TbInvNo').val();
                    Item_Code = $(this).find("#code").html();
                    SaleQty = $(this).find("#itemqty").html();
                    UnitRP = $(this).find("#itemprice").html();
                    a.push(Item_Code + "," + SaleQty + "," + UnitRP);





                });


                var allData = {

                    InvNo:$('#TbInvNo').val(),
                    VAT: $('#TbGST').val(),
                    GrossSale: $('#TbOrderTotal').val(),
                    discount: $('#TbDiscount').val(),
                    CusCash: $('#TbCash').val(),
                    CusBal: $('#TbBalance').val(),
                    CrBank: $('#CbBank').children("option:selected").val(),
                    TblId: $('#CbTable').children("option:selected").val(),
                    PymtType: $("input[name='RbCashStatus']:checked").val(),
                    Dinetype: $("input[name='dinetype']:checked").val()


                }

                var posdata = { collection: allData, Data: a }
                $.ajax({
                    url: '@Url.Action("SaveData", "POS")',
                    type: 'POST',
                    data: posdata,
                    success: function (res) {
                        //$.get('/POS/SaveData', function (Data) {
                        //    alert(Data)


                        });

                    }
                });






            }



    });

Here is my controller in which method return InvNo this is exactly what i want to get in front end and display in html input after successfully saving record by using click mention which i have already attach above:

   public JsonResult SaveData(POSMater collection, string[] Data)
        { 

            if (collection.InvNo.ToString() ==null)
            {

                TblPOSMaster master = new TblPOSMaster();
                var maxValue = (from b in db.TblPOSMasters select b.InvNo).FirstOrDefault();
                int MaxInvNo = maxValue + 1;
                collection.InvNo = MaxInvNo;
                master.InvNo = collection.InvNo;
                master.CompId = 1;
                master.ShopId = 1;
                master.Saleperson = 1;
                master.SaleType = "S";
                master.CusId = 1;
                master.saleDate = DateTime.Now;
                master.PymtType = collection.PymtType;
                master.CrBank = collection.CrBank;
                master.CrCardNo = collection.CrCardNo;
                master.GrossSale = collection.GrossSale;
                master.discount = collection.discount;
                master.TaxCodeId = 1;
                master.VAT = collection.VAT;
                master.NetSale = collection.NetSale;
                master.CusCash = collection.CusCash;
                master.CusCardAmt = collection.CusCardAmt;
                master.CreditAmt = collection.CreditAmt;
                master.CusBal = collection.CusBal;
                master.ExchangeRate = 1;
                master.PointEarned = collection.PointEarned;
                master.PointEarnedValue = collection.PointEarnedValue;
                master.PointRedeem = collection.PointRedeem;
                master.InvNo_Sale_Return = collection.InvNo_Sale_Return;
                master.AddBy = collection.AddBy;
                master.AddDate = DateTime.Now;
                master.UpdateBy = collection.UpdateBy;
                master.UpdateDate = DateTime.Now;
                master.Dinetype = collection.Dinetype;
                master.TblId = collection.TblId;
                master.Pax = collection.Pax;
                master.CashStatus = "P";
                master.OrderStatus = "B";
                master.DisAprBy = collection.DisAprBy;
                master.RefNo = collection.RefNo;
                master.DealRmk = collection.DealRmk;
                master.IsDeal = collection.IsDeal;
                master.DlvrId = collection.DlvrId;
                db.TblPOSMasters.Add(master);
                db.SaveChanges();
                for(int i=0;i<Data.Length;i++)
                {
                    string rcvData = Data[i].ToString();
                    string[] arr = rcvData.Split(','); 
                    TblPOSTran Trans = new TblPOSTran();
                    Trans.InvNo = collection.InvNo;
                    Trans.Item_Code = arr[0];
                    Trans.SaleQty = decimal.Parse(arr[1]);
                    Trans.UnitRP = decimal.Parse(arr[2]);
                    db.TblPOSTrans.Add(Trans);
                    db.SaveChanges();
                    return Json(collection.InvNo, JsonRequestBehavior.AllowGet);
                    //return Json(collection.InvNo);
                }


            }
            else
            {


            }

            return Json(collection.InvNo);
        }

Viewing all articles
Browse latest Browse all 67441

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>