情景:
首先,对不起我的英语。 我试图做的是发布形式低谷-POST下列对象:用剃刀在MVC中发布复杂对象列表
public class AppConfigViewModelInput
{
public string Setting { get; set; }
public string Value { get; set; }
}
以下方法:
[HttpPost]
public ActionResult Index(List<AppConfigViewModelInput> listOfAppConfigToUpdate)
{ ... }
但这输入对象仅由两个属性构成视图对象,我用它来显示我的剃须刀页上的数据:
public class AppConfigViewModel : AppConfigViewModelInput
{
public string Description { get; set; }
public string ConfigType { get; set; }
public int ViewOrderInWebAdmin { get; set; }
public string ViewSpecialBackgroundColor { get; set; }
}
我读了很多问题和博客(检查出的问题,以便参考)。最后我能得到我的剃须刀页面下面的代码(我只发布表单代码段):
@model List<PGWebAdmin.Models.AppConfigViewModel>
@{
var itemCnt = 0;
}
@foreach (var item in Model)
{
itemCnt++;
<input type="hidden" name="AppConfigViewModelInput.Index" value="@itemCnt" />
<input type="text" class="input-sm form-control" value="@item.Value" name="AppConfigViewModelInput[@itemCnt].Value"/>
<input type="text" name="AppConfigViewModelInput[@itemCnt].Setting" value="@item.Setting"/>
}
,并通过创建表单:
@using (Html.BeginForm("Index", "AppConfig",
FormMethod.Post, new { @class = "navbar-form navbar-right", role = "search" }))
{
即发布到该方法,并且该方法被击中,但该参数的值为空:
我测试和修正,尝试了几种方法可以做到这一点,但这是很远,我可以拿到了,我不明白发生了什么。
我做错了什么?为什么我仍然无效?
任何帮助将被优先。 谢谢!
参考:
MVC post a list of complex objects
How can I post a list of items in MVC
Posting to a list<modeltype> MVC3
生成你视图中正确使用'for'环或'EditorTemplate'按照[此答案](http://stackoverflow.com/questions/30094047/html-table-to-ado-net-datatable/30094943#30094943) –