0

I am having trouble submitting a model in my MVC application

The models I currently have are these:

public class Category {
  public int Id { get;set;}
  public Category Parent { get;set;}
  public List<CategoryCulture> Cultures { get;set}
}

public class CategoryCulture {
  public int Id { get;set;}
  public string Name { get;set;} 
  public string Culture {get;set;} 
}

When I want to create a new category I want to be able to fill in a X amount of text fields and insert them simultaneously with the Category. But I have no idea how I should bind the CategoryCulture to the Category model.

Robbert Stevens
  • 316
  • 3
  • 17
  • Do you mean dynamically create new `CategoryCulture` objects associated with the category? –  Nov 24 '14 at 07:25
  • Yes, I get a form where I can specify the parent of the category, and I get name fields for X cultures to fill in. I do not know how associate the input fields I have, with the `CategoryCulture` – Robbert Stevens Nov 24 '14 at 07:27
  • 1
    check list binding with mvc – Vishal Sharma Nov 24 '14 at 07:36
  • 1
    To render controls for existing `CategoryCulture` you need a `for` loop. `for(int i = 0; i < Model.Cultures.Count; i++) { @Html.TextBoxFor(m => m[i].Name) }`. For dynamically adding a new `CategoryCulture`, you need javascript/jquery. [Refer this example](http://stackoverflow.com/questions/24026374/adding-another-pet-to-a-model-form/24027152#24027152) –  Nov 24 '14 at 07:46

0 Answers0