.NET MVC: pass an array of complex objects or lists from a view to a controller

I want to pass an array of a list from a view to a controller when submitting a form. I can pass simple values ​​using the Html.hidden () function. But how can I pass a complex object or List array

+3
source share
2 answers

You can pass the list to the view model using Html.hiddenfor each list item.

, for (foreach ). :

@for (var i = 0; i < Model.Nutrients.Count(); i++) 
{
  // This ensures that the list of nutrients is passed in the view model back to the controller
  @Html.HiddenFor(m => m.Nutrients[i].Name);
  @Html.HiddenFor(m => m.Nutrients[i].Id);
}
0

Source: https://habr.com/ru/post/1754260/


All Articles