asp.net-mvclinqdrop-down-menu

mvc fill dropdownlist


i use this code to fill dropdownlist

ViewData["projectType"] = new SelectList  
  (_dataManager.Project.ProjectTypeList(), "Id", "Name");

but what i must do if i want to use not one table column but two or more columns? for example

ViewData["projectType"] = new SelectList  
  (_dataManager.Project.ProjectTypeList(), "Id", "Name1"+"Name2");

Solution

  • Just add a property to your model ViewModel:

    public partial class Project
    {
        public string FullName 
        {
            get { return Name1 + Name2; }
        }
    }
    

    and use this property:

    ViewData["projectType"] = new SelectList(
        _dataManager.Project.ProjectTypeList(), 
        "Id", 
        "FullName"
    );