我有以下cshtml表单:
model Scraper.Facade.PlayerRow
@using (Html.BeginForm("Calculate", "Home", FormMethod.Post))
{
<table class="table table-striped table-bordered table-condensed table-responsive table-hover">
@foreach (var player in Model.AttribsPlayerLine)
{
<thead>
<tr class="success">
@foreach (var attrib in player.AttribsPlayerList)
{
//@Html.DisplayNameFor(x => Model.tytul)
<th data-field="@attrib.attribName">@Html.DisplayFor(x => attrib.attribName) </th>
}
</tr>
<tr class="active">
@foreach (var attrib in player.AttribsPlayerList)
{
<td data-field="@attrib.attribValue">@Html.TextBoxFor(x => attrib.attribValue)</td>
}
</tr>
</thead>
}
</table>
<input class="btn-danger" type="submit" name="Next >>" value="Next >>" />
}
显示正确,然后我试图在以下控制器 ActionResult 中获取模型
[HttpPost]
public ActionResult Calculate(PlayerRow model)
{
GenericHelper _genericHelper = new GenericHelper();
return View();
}
但是 PlayerRow 模型始终为空。
我究竟做错了什么?
这是我的模型定义
public PlayerRow LoadHtmlDoc(string fileLocation)
{
List<Attrib> attribsHeaderList = new List<Attrib>();
var playerRow = new PlayerRow();
playerRow.AttribsPlayerLine = new List<AttribLine>();
var htmlDoc = new HtmlDocument { OptionFixNestedTags = true };
// There are various options, set as needed
// filePath is a path to a file containing the html
htmlDoc.Load(fileLocation);
}
public class PlayerRow
{
public List<AttribLine> AttribsPlayerLine;
}
更新
大家好,我改变了我的应用程序的逻辑,基本上有2个列表,其中包含标题属性和所有玩家的属性,所以现在只有2个类,我改变了这样的cshtml,它现在正在工作: -
@using (Html.BeginForm("Calculate", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<table class="table table-striped table-bordered table-condensed table-responsive table-hover">
<tr>
@for (int k = 0; k < Model.HeaderAttributes.Count; k++)
{
<td>
@Html.DisplayFor(x => x.HeaderAttributes[k].AttributeName)
@Html.HiddenFor(x => x.HeaderAttributes[k].AttributeName)
</td>
}
</tr>
@for (int i = 0; i < Model.PlayerList.Count; i++)
{
<tr>
<td>
@Html.DisplayFor(x => x.PlayerList[i].PlayerName)
@Html.HiddenFor(x => x.PlayerList[i].PlayerName)
</td>
@for (int j = 0; j < Model.PlayerList[i].AttributesList.Count; j++)
{
<td>
@Html.DisplayFor(x => x.PlayerList[i].AttributesList[j].AttributeValue)
@Html.HiddenFor(x => x.PlayerList[i].AttributesList[j].AttributeValue)
</td>
}
</tr>
}
</table>
<input class="btn-danger" type="submit" name="Next >>" value="Next >>" />
}
现在我的问题是,谁来授予答案,因为我可以说大多数答案对我的解决方案非常有帮助