RadioButtonFor
withtrue
またはas 2nd パラメータの実装を見たところですが、false
JavaScript を使用してチェック値を設定するにはどうすればよいですか?
Id を介してラジオボタンのチェック済みの値を設定し、ビューJavaScript
でのみ使用する既存のコードが既にあります。@Html.RadioButton
しかし、私が今欲しいのは、 を使用することRadioButtonFor
です。どうすればいいですか?私のアクティブと非アクティブの ID は同じで、どちらの rbtn も値が異なるだけです。
PS: 動作しないコードは JavaScript の下部にあります
モデル:
[Display(Name = "Status")]
public string userStatus { get; set; }
意見:
@Html.LabelFor(m => m.userStatus)
@Html.LabelFor(m => m.userStatus, "Active")
@Html.RadioButtonFor(m => m.userStatus, true)
@Html.LabelFor(m => m.userStatus, "Inactive")
@Html.RadioButtonFor(m => m.userStatus, false)
Javascript の一部:
//columnData - represents the column index in my table
//fieldId - id of the fields (e.g. text = userDesc, radio = userStatus)
for (i = 0; i < columnData.length; i++) {
//Evaluates what type an input is
var elmntType = document.getElementById(fieldId[i]).getAttribute("type");
if (elmntType == "text") {
document.getElementById(fieldId[i]).value = rowSelected.cells[i].innerHTML.trim();
} else if (elmntType == "radio") {
var status = rowSelected.cells[i].innerHTML.trim();
//I just invented this but it's not working
if (status == "Active") {
document.getElementById(fieldId[i]).checked = true;
} else {
document.getElementById(fieldId[i]).checked = false;
}
}
}