关于是/否radiobutton答案我几乎没有问题。
我正在尝试将所选值(radiobutton值)保存到我的数据库中的Answers表中。但是所选的值将返回null。
查看
@using (Html.BeginForm("SaveAnswers", "MyController"))
<td>@Html.RadioButtonFor(model => model.answerValue[i], true) Yes @Html.RadioButtonFor(model => model.answerValuer[i], false) No</td>
<input type = "submit" name = "actionType" value = "SaveAnswers"/>
模型
Public List <bool> answerValue {get;set;}
控制器
public ActionResult SaveAnswers(string actionType)
{
Answers userAnswers = new Answers();
if (ModelState.IsValid)
{
if (actionType == "Save")
{
userAnswers.value = model.answerValue[i];
db.SaveChanges();
}
}
return View(actionType);
}
它没有在我的控制器中选择它并显示它的空...
答案 0 :(得分:0)
请尝试将模型作为输入添加到控制器中,您需要将模型替换为模型的类名
public ActionResult SaveAnswers(string actionType, Model model)
{
Answers userAnswers = new Answers();
if (ModelState.IsValid)
{
if (actionType == "Save")
{
userAnswers.value = model.answerValue[i];
db.SaveChanges();
}
}
return View(actionType);
}