I have a controller with a viewModel that contains an IEnumerable in it and I have a form which is constructed by a jQuery control.
When I post back to the control I want to collect all the rows of hidden fields that were collected into an IEnumerable.
Here's an example view model:
public class MyViewModel
{
public IEnumerable<SelectListItem> GeneratedItems { get; set; }
}
In the jQuery I create rows in a table with hidden fields like this:
<input class="hiddenValue" name="' + controlName + '_guid" type="hidden" value="' + guid + '"></input>
And then in the POST method of the controller I receive the posted model.
Here's my problem... if I accept a IEnumerabe then all the guids are collected correctly. But I haven't managed to get it to return a IEnumberable.
I have tried adding two hidden fields and trying something like this:
<input class="hiddenValue" name="' + controlName + '.Text" type="hidden" value="' + text + '"></input>
<input class="hiddenValue" name="' + controlName + '.Value" type="hidden" value="' + guid + '"></input>
But that returns an empty array.
Can someone help me arrange the hidden fields so that it will give me a list of the object I want?
Many thanks