I have a form in my view that contains a listbox. The user adds values to the listbox.
When the user pushes the submit-button i want the all the values in the listbox to be placed in my models property that is a List.
Here is the Listbox in my view:
@Html.ListBoxFor(m => m.Ingredients, new List<Ingredient>(), new { @class = "form-control" , @id = "Ingredients"})
This line show an error and the error is that the List has to contain SelectListItem. Even if i change to that, and also change it in my viewmodel, it still doesnt work.
This is my viewmodel:
public class RecipeModel
{
public int Id { get; set; }
public string Name { get; set; }
public List<Ingredient> Ingredients { get; set; }
public string Description { get; set; }
public string ImageUrl { get; set; }
public List<RecipeModel> Recipes { get; set; }
}
This is my controller:
[HttpPost]
public void SaveRecipe(RecipeModel model)
{
RecipeDb.SaveRecipe(Mapper.Map<Recipe>(model));
}
What i want is that in the controller, I want the models List Ingredients to be populated by all the items/values in the listbox from the view but I cant figure it out.
Aucun commentaire:
Enregistrer un commentaire