Multiple Data Entry--MvcShakil Ahmed9yAsked Nov 25, 2017, 1:54 AM ESTSolvedShareLinkedInXCopy linkSaveI am trying to save multiple data but it takes only first row.pls somebody help
Multiple Data Entry--MvcShakil Ahmed9yAsked Nov 25, 2017, 1:54 AM ESTSolvedShareLinkedInXCopy linkSaveI am trying to save multiple data but it takes only first row.pls somebody help
Ranjit PowarRank #553 · 4.4K reputation9y agoPosted Nov 26, 2017, 3:54 AM EST✓ Accepted answer0Following code will work @using (Html.BeginForm(FormMethod.Post)){int i = 0;@*@Html.AntiForgeryToken()*@item@*@Html.ValidationSummary(true, "", new { @class = "text-danger" })*@NameQuantity@foreach (var item2 in Model){@**@i++;}}0
Ranjit PowarRank #553 · 4.4K reputation9y agoPosted Nov 25, 2017, 2:10 AM EST0Please post your code.0
Shakil Ahmed51 reputation9y agoPosted Nov 25, 2017, 2:30 AM EST0@model IEnumerable@{ ViewBag.Title = "Create";}Create@using (Html.BeginForm(FormMethod.Post)){ @*@Html.AntiForgeryToken()*@ item @*@Html.ValidationSummary(true, "", new { @class = "text-danger" })*@ Name Quantity @foreach (var item2 in Model) { @* *@ } }-------------------------------------------------- // GET: items/Create public ActionResult Create() { List class1List = new List { new item(){ Name = null, Qtty=null }, new item(){ Name = null, Qtty=null }, new item(){ Name = null, Qtty=null } }; return View(class1List); } [HttpPost] //[ValidateAntiForgeryToken] public ActionResult Create(List itemList) { foreach (var i in itemList) { db.item.Add(i); db.SaveChanges(); } return RedirectToAction("Index"); }0Ranjit PowarRank #553 · 4.4K reputation9y agoPosted Nov 25, 2017, 3:22 AM EST0Change loop as below @foreach (var item2 in Model){int i=0; @**@ i++; }0Shakil Ahmed51 reputation9y agoPosted Nov 25, 2017, 6:28 PM EST0 i applied your code but itemlist show null.0Shakil Ahmed51 reputation9y agoPosted Nov 26, 2017, 6:29 PM EST0Thanks Brother.God Bless You.0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ranjit PowarRank #553 · 4.4K reputation9y agoPosted Nov 25, 2017, 3:22 AM EST0Change loop as below @foreach (var item2 in Model){int i=0; @**@ i++; }0
Shakil Ahmed51 reputation9y agoPosted Nov 25, 2017, 6:28 PM EST0 i applied your code but itemlist show null.0
Ranjit PowarRank #553 · 4.4K reputationPosted Nov 26, 2017, 3:54 AM EST
item
Ranjit PowarRank #553 · 4.4K reputationPosted Nov 25, 2017, 2:10 AM EST
Shakil Ahmed51 reputationPosted Nov 25, 2017, 2:30 AM EST
Create
item
Ranjit PowarRank #553 · 4.4K reputationPosted Nov 25, 2017, 3:22 AM EST
Shakil Ahmed51 reputationPosted Nov 25, 2017, 6:28 PM EST
Shakil Ahmed51 reputationPosted Nov 26, 2017, 6:29 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts