Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am creating controls using viewbag that has a list of item

C#
public ActionResult Create()

        {
            var savedAdditionalFields = afs.getAllStudentFieldss(1);
            ViewBag.AdditionalFieldList = savedAdditionalFields;
            return View();
        }


In the view i am using

C#
@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>

}
The controls and labels are created.
Now i am saving the items in database using


C#
[HttpPost]

     public ActionResult Create(StudentAdditionalDetail additionalFields)

            {   
                ads.AddAdditionalDetails(additionalFields);//calls the insert method

                return RedirectToAction("Index");

            }


But only the first Textbox's data is getting saved in database.I think i need to iterate my [HttpPost] Create Method.But not sure where should i put the code that will iterate throughout my Create View and all the items in

> model.AdditionalInfo

will be saved into database
Posted
Updated 3-Sep-13 1:00am
v2

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900