我有一个数据表,我正在写每行旁边的复选框。但是,当我提交页面时,没有任何内容传递给我的方法。任何帮助表示赞赏!我的代码在
之下型号:
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");
}
答案 0 :(得分:0)
您的控制器将采用您通常需要的任意内容和FormCollection collection
,并按name
属性collection["checkBoxName"]
属性获取复选框:{{1}}