I am using MVC4 C# Razor view and MS SQL Server. I need to insert a list/array value from controller to sql server. I am passing values from view to controller and getting the values in controller.
My data structures are -
{sid: "101", m1Qty: "1", m2Qty: "3", m3Qty: ""}
{sid: "102", m1Qty: "5", m2Qty: "6", m3Qty: ""}
{sid: "103", m1Qty: "8", m2Qty: "0", m3Qty: ""}
Above data needed to insert my table (tbl_monthqty) in the below order. ID auto generated - 
ID  SID     MonthID   mQty
1   101        1       1 
2   102        1       5
3   103        1       8
4   101        2       3
5   102        2       6
If any value null or 0, need to ignore
MonthID is for example - m1Qty = 1, m2Qty = 2, m3Qty = 3
My controller (C#) is -
[HttpPost]
public JsonResult SaveQty(IList<AllQty> model)
{
    var list = new [] { model };
    var count = list.Count();
    DataTable dt = new DataTable();
    dt.Columns.Add("SID");
    dt.Columns.Add("MonthID");
    dt.Columns.Add("mQty");
    for(int i=0; i<count; i++)
    {
        //dt.Rows.Add();
        // Not sure what I will do here
    }
    return Json(new { success = true });
}
My class is -
public class AllQty
{
    public int SID { get; set; }
    public int MonthID { get; set; }
    public int mQty { get; set; }
} 
I am getting the list value in controller but not sure how I will insert those list/array values in my table. I have tried few asked questions like this but did not work.
 
     
    