Saving Dynamic Form Fields to Database with Fixed Values in MVC

kadir 60 Reputation points
2024-05-23T07:33:53.8266667+00:00
    [HttpPost]

    [ValidateAntiForgeryToken]

    public ActionResult Create(EgitimSeminerViewModel model)

    {

        if (ModelState.IsValid)

        {

            for (int i = 0; i < model.EgitimSeminerBilgiList.Count; i++)

            {

                TBL_EgitimSeminerBilgi item = new TBL_EgitimSeminerBilgi();

                item.EgitimKonu = model.EgitimSeminerBilgiList[i].EgitimKonu;

                item.EgitimKurum = model.EgitimSeminerBilgiList[i].EgitimKurum;

                item.EgitimSuresi = model.EgitimSeminerBilgiList[i].EgitimSuresi;

                db.TBL_EgitimSeminerBilgi.Add(item);

            }

            db.SaveChanges();

            return RedirectToAction("Create"); // Or other redirection

        }

        return View(model);

    }

	Hello everyone, friends, my goal here is to record according to the number of incoming data, no problem until this part 

	but I also want to add the GeneralInfoid and value fields in the same table, so these fields will be fixed.

	item.GenelBilgiid = 12; item.deger = false; no matter how many times the data is added
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,417 questions
{count} votes