的选择数值没有得到回发时,我组我的单选按钮,radiobuttonfor分组剃刀mvc5
因此,与此SelectedQuestionId 为空白
<div class="row">
<div class="col-md-4">
<div class="form-group">
@Html.HiddenFor(x => x.UserResponses[0].QuestionId)
@Html.RadioButtonFor(x => x.UserResponses[0].SelectedQuestionId, Model.UserResponses[0].QuestionId, new { Name ="selectone"})
@Html.DisplayTextFor(x => x.UserResponses[0].QuestionText)
@Html.HiddenFor(x => x.UserResponses[0].QuestionText)
@Html.HiddenFor(x => x.UserResponses[0].InputType)
@Html.HiddenFor(x => x.UserResponses[0].Points)
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<span class="text-muted">@Html.DisplayTextFor(x => x.UserResponses[0].Points)</span> @Html.LabelFor(x => x.UserResponses[0].Points, new { @class = "text-muted" })
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
@Html.HiddenFor(x => x.UserResponses[1].QuestionId)
@Html.RadioButtonFor(x => x.UserResponses[1].SelectedQuestionId, Model.UserResponses[1].QuestionId, new { Name = "selectone"})
@Html.DisplayTextFor(x => x.UserResponses[1].QuestionText)
@Html.HiddenFor(x => x.UserResponses[1].QuestionText)
@Html.HiddenFor(x => x.UserResponses[1].InputType)
@Html.HiddenFor(x => x.UserResponses[1].Points)
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<span class="text-muted">@Html.DisplayTextFor(x => x.UserResponses[1].Points)</span> @Html.LabelFor(x => x.UserResponses[1].Points, new { @class = "text-muted" })
</div>
</div>
</div>
但当下我删除分组从radiobuttonfor然后一切运作良好,并SelectedQuestionId填充questionid。因此,用这些替换上面的RadioButtonFor允许在发布表单时填充SelectedQuestionId。 上面的代码是基于这个question,虽然我已经问了一个相关的问题here - 这个问题是完全分开的。
@Html.RadioButtonFor(x => x.UserResponses[0].SelectedQuestionId, Model.UserResponses[0].QuestionId)
@Html.RadioButtonFor(x => x.UserResponses[1].SelectedQuestionId, Model.UserResponses[1].QuestionId)