Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to make a dropdownlist from a seed model (populated table) and pass selected value to a string type variable in another model?
--------------------------
class team {string teamID; string Name_team;} //model
*************************
//seed in configuration file
*************************
new ListTeam>
           {new Team{teamID="Architect";, Name_team="Architect"},
           new Team{teamID="PM";, Name_team="Project_Management"}.ForEach(i => context.DBTeams.AddOrUpdate(i));
--------------------------
class User{                          //model
string name {get;set;}
string team_of_user{get;set;}
}
--------------------------
class mainModel                           //model
{[key] string mm {get;set;}
User usr=new User();
Team tm=new Team();
}
------
VIEW
@Html.DropDownListFor(m=>m.usr.team_of_user, new SelectList(...??));//what do i write here


How to make a drop down here which is populated from TeamDB (Database context),
and whose selected value must pass to the other model..?
Posted

1 solution

I used ViewBag
and in VIEW,

@Html.LabelFor(model => model.current_position, htmlAttributes: new { @class = "control-label col-md-2" })

@Html.DropDownListFor(model => model.current_position, (IEnumerable<SelectListItem>)ViewBag.positionsfromDB)

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900