tôi đang thực hiện giá trị trên ViewModel bạn có thể mang nó từ mô hình nếu bạn muốn
ViewModel
public class PropMgmtViewModel
{
public Property Property { get; set; }
public IEnumerable<Property> Properties { get; set; }
public SelectList Cities { get; private set; }
static Dictionary<int, string> CitiesDict = new Dictionary<int, string>()
{
{ 1 ,"Chicago"},
{ 2 ,"New York"},
{ 3 ,"Zimbabwe"},
};
public PropMgmtViewModel()
{
Cities = new SelectList(CitiesDict, "Key", "Value");
}
xem mã tôi cũng bao gồm các Thuộc tính seleclist để chỉ cho bạn cách nó được thực hiện
@foreach (var radioitem in Model.Cities)
{
@radioitem.Text;
@Html.RadioButtonFor(model => model.Property.City, radioitem.Value);
}
@Html.DropDownListFor(model => model.Property.City, Model.Cities,"Seciniz")
bạn có thể ràng buộc các mục trong danh sách lựa chọn với các nút vô tuyến quá .. – c0demaster