I have a view that handles a ViewModel as below,
public class MyVM {
public Exercise exer{ get; set; }
public List<Category> categories { get; set; }
public List<ExerciseInput> inputs { get; set; }
}
The view has multiple exercises based on the number of categories in the database. With a for loop i create the initial exercises for each category, the user can also add a question to each category too (as linked in has in it profile page, you can add experience to the profile), my issue is saving all this data. or updating existing data. I used Editor templates, but still can figure out how to handle multiple data for each category of the same type (ExceriseInput). Thanks in advance.
Controller code,
public ActionResult viewExcerciseDetails(int Id)
{
var vm = new MyVM();
vm.exer= db.Exercise .SingleOrDefault(m => m.exerId == Id);
vm.categories = db.Categories.OrderBy(m => m.orderNum).ToList();
vm.inputs = db.ExerciseInput.Where(m => m.exerId == Id).ToList();
return View(vm);
}
A piece of code where the for loop in the view
@for (var i = 0; i < data.Count(); i++)
{
@Html.EditorFor(m => data[i])
}