Keep ViewModel list populated from HTTPGet to HTTPPost ActionResult

333 Views Asked by At

In an MVC5 internet application, how can I keep the contents of a ViewModel List, between the HTTPGet request and the HTTPPost request.

I have done some searching, but am not sure exactly what term to search for.

Here is my situation:

I have a ViewModel, that has the following list populated in the HTTPGet ActionResult:

public List<string> azureBlobFullFileNames { get; set; }

In the HTTPPost ActionResult, the list is null.

How can I still have the list populated with values in the HTTPPost ActionResult?

I have added the following code after the @Html.AntiForgeryToken() View line of code:

@Html.HiddenFor(model => model.azureBlobFullFileNames)

However, the list is still null in the HTTPPost ActionResult.

Can I please have some help with this code?

Thanks in advance

1

There are 1 best solutions below

0
On BEST ANSWER

Generate a control for element in the collection using a for loop.

for(int i = 0; i < Model.azureBlobFullFileNames.Count; i++)
{
  @Html.HiddenFor(m => m.azureBlobFullFileNames[i])
}