Mvc4uses FormCollection to add data in batches. mvc4formcollection
// POST:/Assay_BillMain/Create
/// <Summary>
/// Add data in batches
/// </Summary>
/// <Param name = "assay_billmain"> </param>
/// <Param name = "fc"> </param>
/// <Param name = "assau_billdetail"> </param>
/// <Returns> </returns>
[HttpPost]
[ValidateAntiForgeryToken]
Public ActionResult Create (Assay_BillMain assay_billmain, FormCollection fc, Assay_BillDetail assau_billdetail)
{
Int BillMain_PTR = 0;
String [] ItemNoArr = new string [] {};
String [] TankNoArr = new string [] {};
String [] ItemArr = new string [] {};
String [] MeiRangeArr = new string [] {};
String [] AnalyseRangeArr = new string [] {};
String [] ResultArr = new string [] {};
String [] MethodsArr = new string [] {};
String [] ChemicalsArr = new string [] {};
String [] QuantityArr = new string [] {};
String [] FinalResultArr = new string [] {};
String [] FinalTimeArr = new string [] {};
If (ModelState. IsValid)
{
Db. Assay_BillMain.Add (assay_billmain );
Db. SaveChanges ();
String strMaxSql = "select * from dbo. Assay_BillMain where RKEY = (select max (RKEY) from dbo. Assay_BillMain );";
DataSet ds = SqlHelper. Query (strMaxSql );
If (ds. Tables [0]. Rows. Count> 0)
{
BillMain_PTR = Convert. ToInt32 (ds. Tables [0]. Rows [0] ["RKEY"]);
}
ItemNoArr = fc ["ItemNo"]. Split (',');
TankNoArr = fc ["TankNo"]. Split (',');
ItemArr = fc ["Item"]. Split (',');
MeiRangeArr = fc ["MeiRange"]. Split (',');
AnalyseRangeArr = fc ["AnalyseRange"]. Split (',');
ResultArr = fc ["Result"]. Split (',');
MethodsArr = fc ["Methods"]. Split (',');
ChemicalsArr = fc ["Chemicals"]. Split (',');
QuantityArr = fc ["Quantity"]. Split (',');
FinalResultArr = fc ["FinalResult"]. Split (',');
FinalTimeArr = fc ["FinalTime"]. Split (',');
For (int n = 0; n <ItemNoArr. Length; n ++)
{
Assau_billdetail = new Assay_BillDetail ();
Assau_billdetail.BillMain_PTR = BillMain_PTR;
Assau_billdetail.ItemNo = Convert. ToInt16 (ItemNoArr [n]);
Assau_billdetail.TankNo = TankNoArr [n];
Assau_billdetail.Item = ItemArr [n];
Assau_billdetail.MeiRange = MeiRangeArr [n];
Assau_billdetail.AnalyseRange = AnalyseRangeArr [n];
Assau_billdetail.Result = ResultArr [n];
Assau_billdetail.Methods = MethodsArr [n];
Assau_billdetail.Chemicals = ChemicalsArr [n];
Assau_billdetail.Quantity = QuantityArr [n];
Assau_billdetail.FinalResult = FinalResultArr [n];
Assau_billdetail.FinalTime = FinalTimeArr [n];
Db. Assay_BillDetail.Add (assau_billdetail );
Db. SaveChanges ();
}
Return Content ("<script type = 'text/javascript '> alert ('document input successful! '); Window. location. href ='/Assay_BillMain/create' </script> ");
}
ViewBag. Process_PTR = new SelectList (db. Assay_Process, "RKEY", "ProcessName", assay_billmain.Process_PTR );
ViewBag. Type_PTR = new SelectList (db. EnmItemValues, "RKEY", "ItemValue", assay_billmain.Type_PTR );
Return View (assay_billmain );
}