public static SelectList GetSelectList_Block(object ProjectId, object sValue) { var selectListItems = new List <SelectListItem>(); BlockRepository blockRepository = new BlockRepository(new Domain.RealEstate.ErpRealEstateDbContext()); //SelectListItem itemEmpty = new SelectListItem(); //itemEmpty.Text = App_GlobalResources.Wording.ContractTypeName; //itemEmpty.Value = null; //selectListItems.Add(itemEmpty); try { if (ProjectId != null) { int id = Convert.ToInt32(ProjectId); var q = blockRepository.GetAllBlock().Where(item => item.ProjectId == id).OrderBy(item => item.Name).ToList(); foreach (var i in q) { SelectListItem item = new SelectListItem(); item.Text = "Block " + i.Name; item.Value = i.Id.ToString(); selectListItems.Add(item); } } } catch { } var selectList = new SelectList(selectListItems, "Value", "Text", sValue); return(selectList); }