Monday, 6 June 2016

Post Form data and list with ajax in mvc

No comments
.js


var lstMultiModels = [];

 lstMultiModels.push({ inid: $(this).find('.txtOutInId').val(), price: $(this).find('.price').val(), qty: $(this).find('.Qty').val() });      
var lstModel = JSON.stringify({ date: $('#date').val(), id: $('#id').val(), 'lstMultiModels': lstMultiModels});

$.ajax({
        type: "POST",
        url: "/Drugs/Out",
        data: lstModel,
        async: true,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (responseData) {
        },
        error: function () { }
    })

lstMultiModels.cs

public int inid{ get; set; }
public int price{ get; set; }
public int qty{ get; set; }

Models.CS

public DateTime date  {get; set; }
public int id {get; set; }
public List<lstMultiModels> lstMultiModels{get; set; }

Controller.cs

        [HttpPost]
        public ActionResult Out(Models Models)
        {

        }