我正在使用BootStrap DataTable API将数据添加到部分视图中,
$(function () {
var table= $('#showExtract').DataTable();
table.row.add($(
'<tr>' +
'<td> @Html.DisplayFor(x=> x.ExtractName) @Html.HiddenFor(x=> x.ExtractName) ' +
'</td>' +
'<td>' +
' <div class="form-group col-lg-12">' +
'<div class="col-lg-12"> @Html.TextBoxFor(x=> x.secondName, new { @class = "input-sm col-lg-12" }) ' +
' </div>' +
'</div>' +
'</td>' +
'<td> @Html.CheckBoxFor(showExtract => showExtract.IsChecked)' +
'</td>' +
'</tr>'
)).draw(false);
现在我的视图正在填充,并且没有任何错误,问题是当我 将此数据表发布到我的控制器,它始终为null 我的控制器动作看起来像
public ActionResult showExtract(IEnumerable<showExtractFile> model)
{
/// var selectedItems = model.Where(x => x.IsChecked);
//var format = string.Join(",", selectedItems.Select(x => x.ExtractName));
return Content("Thank you for selecting " + "format");
}
在此操作模型中始终为null,我的视图发布数据如下
@using (Html.BeginForm("showExtract", "userSupport", FormMethod.Post))
{
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<h3 class="box-title">Hover Data Table</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="form-group">
<table id="showExtract" class="table table-bordered table-hover">
<thead>
<tr>
<th>Extract Name</th>
<th>Update Name</th>
<th>Select</th>
</tr>
</thead>
@Html.EditorForModel()
</table>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-md">
<i class="fa fa-gears"></i>Process
</button>
</div>
</div>
</div>
</div>
}
我的模特看起来像这样
public class showExtractFile
{
public string ExtractName { get; set; }
public string SecondName{ get; set; }
public bool IsChecked { get; set; }
}
我在填充后检查了控件的名称,并且怀疑它的命名约定会导致问题
<input class="input-sm col-lg-12 ui-autocomplete-input" name="[23].SecondName" type="text" value="A. Q. & COMPANY INTERNATIONAL" autocomplete="off">
检查发布的请求后,我可以得到以下结果
showExtract_length: 10
[23].ExtractName: A.Q. & COMPANY INTERNATIONAL
[23].SecondName: A. Q. & COMPANY INTERNATIONAL
[23].IsChecked: false
[59].ExtractName: AA FOODS IMPORTERS AND DISTRIBUTORS
[59].SecondName:
[59].IsChecked: false
[50].ExtractName: ADIL STEEL FURNACE
[50].SecondName: ADIL STEEL FURNACE
[50].IsChecked: true
[50].IsChecked: false