情景:
首先,對不起我的英語。 我試圖做的是發佈形式低谷-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) –