In mvc3, There is only radiobutton and there is no radiobuttonlist, but it must be used in projects. What should I do?
Answer: Do it on your own.
After implementation: There is a file confidentiality level, such as top secret, confidential, General, etc., which needs to be displayed on the page and can be controlled in the background which is selected.
The implementation steps are as follows:
1. Load the confidentiality level and whether or not to a list.
View code
List<KeyValuePair<string, bool>> secrecyList = new List<KeyValuePair<string, bool>>(); var secrecyLevelList = baseTypeDetailRepository.GetBaseTypeDetailList(BaseType.SecrecyLevel); foreach (var item in secrecyLevelList) { if (auth.SecrecyLevel == item.Caption) { secrecyList.Add(new KeyValuePair<string, bool>(item.Caption, true)); } else { secrecyList.Add(new KeyValuePair<string, bool>(item.Caption, false)); } }
2. traverse the list on the page to check whether the list is selected and enter radiobutton.
View code
@if (ViewBag.SecrecyList != null) { foreach (KeyValuePair<string, bool> item in ViewBag.SecrecyList) { if (item.Value) { @Html.RadioButton("SecrecyLevel", item.Key, new { @id = item.Key, @checked = true }) <span> @item.Key </span> } else { @Html.RadioButton("SecrecyLevel", item.Key, new { @id = item.Key }) <span> @item.Key </span> } } }
3. the backend can receive the selected file confidentiality level.
VaR secrecylevel = Collection ["secrecylevel"];