I have a Region
class like this:
public class Region
{
public int Id { get; set; }
public int Name { get; set; }
public int ParentId { get; set; }
}
And Person
has region:
public class Person
{
public int Id { get; set; }
public int Name { get; set; }
public int SurName { get; set; }
public int RegionId { get; set; }
}
But, it is not like tree node. There are only 2 floors. Countries and it's sub regions - cities. I use bootstrap template.
I collect this regions like this list:
Country1 //need to disable this
City1
City2
City3
Country2 //need to disable this
City1
City2
In person create action:
Viewbag.Regions = new SelectList(MyRepository.LoadRegions(), "Id", "Name");
And in view:
@Html.DropDownListFor(model => model.RegionId, ViewBag.Regions as IEnumerable<SelectListItem>, "-", new { data_rel = "chosen", @id = "region" })
Finally, I need when dropdown opens, to disable countries, it is possible to select only cities.
How can I disable elements in dropdownlis which parentId == 0
?