如何将从 radiobuttonfor 检索到的 id 传递给 MainPage 控制器 - 视图中的 Edit1 actionresult。任何帮助将不胜感激!谢谢!
//在for循环中查看显示内容和单选按钮
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.SurveyTitle)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateCreated)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateClosing)
</td>
<td>
@Html.DisplayFor(modelItem => item.User)
</td>
<td>
@Html.RadioButtonFor(modelItem => item.SurveyId, new {id = item.SurveyId})
</td>
</tr>
}
<button type="submit" class="btn btn-primary" id="edit">Edit</button>
//按钮的脚本来检测选择了哪个单选按钮id并提交
<script>
$('#edit').click(function () {
var id = $('input[type=radio]:checked').val();
alert(id);
});
</script>
//控制器获取id并取出surveyid
[HttpPost]
public ActionResult Edit1(int id=0)
{
survey survey = db.surveys.Single(s => s.SurveyId == id);
if (survey == null)
{
return HttpNotFound();
}
return View(survey);
}