@question.QuestionD">
<input id="@question.QuestionId" type="radio" value="@question.QuestionDescription" name="@string.Format("name_{0}", question.Group)" checked=@question.IsSelected"checked":false /> @question.QuestionDescription
根据question.IsSelected的值,复选框应被选中或不被选中。
但无论IsSelected属性的真假如何,单选按钮始终处于选中状态。您能指出选中属性中的错误所在吗
发布于 2012-01-26 14:41:58
如果您为它的checked
属性提供了任何东西,它将被设置为checked。我可以选择根据IsSelected
属性添加整个checked='checked'
值,当值为false时省略它。
<input id="@question.QuestionId" type="radio" value="@question.QuestionDescription" name="@string.Format("name_{0}", question.Group)" @(question.IsSelected?"checked='checked'":"") /> @question.QuestionDescription
发布于 2012-01-26 14:44:04
你可以这样做
@{
string checkedAttribute = string.Empty;
if (question.IsSelected)
{
checkedAttribute = "checked=\"checked\"";
}
}
<input id="@question.QuestionId" type="radio" value="@question.QuestionDescription" name="@string.Format("name_{0}", question.Group)" @checkedAttribute/>
https://stackoverflow.com/questions/9019764
复制