我有一个数据表,我在每一行旁边都写了复选框。但是,当我提交页面时,没有任何东西传递给我的方法。任何帮助表示赞赏!我的代码如下
模型:
foreach (int analysis in ChemList.Select(d => d.analysisId).Distinct())
{
DataRow dr = GridData.NewRow();
GridData.Rows.Add(dr);
GridData.Rows[gridrow][0] = "<input type='checkbox' value="+checknum+" checked>";
GridData.Rows[gridrow][1] = ChemList[listrow].analysisId;
GridData.Rows[gridrow][2] = ChemList[listrow].analysisTime;
GridData.Rows[gridrow][3] = ChemList[listrow].sampleType;
GridData.Rows[gridrow][4] = ChemList[listrow].productId;
确保写入复选框的模板:
@using System;
@model TheManhattanProject.Models.CellValueViewModel
<td>
@{if(Model.Value.StartsWith("<input type='checkbox'"))
{
@Html.Raw(Model.Value);
}
else
{
@Html.DisplayFor(x => x.Value);
}
}
</td>
看法:
@using (Html.BeginForm("Average", "Home", "POST"))
{
<input type="submit" value="Average" />
<div id="grid">
<table id="example" class ="gridTable">
<thead class="gridHead">
<tr>
@Html.DisplayFor(x => x.Columns)
</tr>
</thead>
<tbody>
@Html.DisplayFor(x => x.Rows)
</tbody>
</table>
</div>
}
控制器方法(只是一个占位符,但值保持为空):
[HttpPost]
public ActionResult Average(params int[] values)
{
return RedirectToAction("Index");
}