保持ViewModel列表从HTTPGet填充到HTTPPost ActionResult

时间:2014-09-21 07:46:16

标签: list asp.net-mvc-5 http-post viewmodel html.hiddenfor

在MVC5互联网应用程序中,如何在ViewModel List请求和HTTPGet请求之间保留HTTPPost的内容。

我做了一些搜索,但我不确定要搜索的是什么术语。

以下是我的情况:

我有一个ViewModel,其中HTTPGet ActionResult填充了以下列表:

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

HTTPPost ActionResult中,列表为空。

如何使用HTTPPost ActionResult中的值填充列表?

我在@Html.AntiForgeryToken()查看代码行之后添加了以下代码:

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

但是,HTTPPost ActionResult中的列表仍然为空。

我可以帮助您使用此代码吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

使用for循环为集合中的元素生成控件。

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