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
You can use Json or see the following example.
http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/
You can pass the list to the view model using Html.hiddenfor each list item.
Html.hidden
, for (foreach ). :
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); }
Source: https://habr.com/ru/post/1754260/More articles:ComplexType HOWTO-defined WSDL list, return from service? - wsdliphone mobile web + удалить панели интерфейса Safari - iphoneUINavigationController and UIViewController dealloc - memorySynchronous message passing in Safari extension - javascriptHow do you extract HTML from an external website into a variable in ColdFusion? - coldfusionIterate over all form fields with selenium in ruby - ruby | fooobar.comIn web2py, can an existing named field be specified as an auto-dialer identifier in an obsolete database? - pythonAndroid emulator does not recognize Hebrew font - androidSaving a file using WWW :: Selenium - perlto load another css for site localization - asp.netAll Articles