I create controls using a viewbag that has a list of items
public ActionResult Create() { var savedAdditionalFields = afs.getAllStudentFieldss(1); ViewBag.AdditionalFieldList = savedAdditionalFields; return View(); }
In the view, I use
Create
@using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> <legend>StudentAdditionalDetail</legend> @foreach (MyClass item in ViewBag.AdditionalFieldList) { <div> @Html.DisplayFor(itemlist=>item.Name) @Html.EditorFor(model=>model.AdditionalInfo) </div> }
Controls and labels are created. Now I save the items in the database using
[HttpPost] public ActionResult Create(StudentAdditionalDetail additionalFields) { ads.AddAdditionalDetails(additionalFields);
But only the first data in the text field is stored in the database. I think I need to repeat my method of creating [HttpPost]. But not sure where I should put the code that will iterate through my entire Create view and all the elements in
model.AdditionalInfo
will be saved in the database
source share