I have two classes:
public class Exercise
{
public Guid Id {get;set;}
public string Name {get;set;}
public List<ExerciseItem> Items {get;set;}
}
public class ExerciseItem
{
public Guid Id {get;set;}
public string Name {get;set;}
public string Content {get;set;}
}
I also have my view for creating an Exercise object. There is a button on that view named "Add exercise item" where I dynamically invoke ajax method for returning a partial view for ExerciseItem objects. The view is returned correctly. This view is as follows:
@model Elang.Models.ExerciseItem
<div>
<input type="hidden" name="Items.Index" value="@Model.Id" />
<input type="hidden" id="Items@(Model.Id)__Id" name="Items[@Model.Id].Id" value="@Model.Id" />
<input type="text" id="Items@(Model.Id)__Content" name="Items[@Model.Id].Content" class="inputText"/>
</div>
The problem is that when I submit the form and my "Create" method is invoked:
[HttpPost]
public ActionResult Create(Exercise exercise)
{
//add exercise to db
//HOWEVER!!
//exercise.Items is empty
}
my Items are null. What am I doing wrong? Can someone give me some advices what should I do to fix the problem?