I have a Controller to load the view:
public ActionResult AssignRole(long id = 0)
{ user UserModel = new user();
int UserId = Convert.ToInt32(id);
IListUsers = new List ();
var query = from Role in db.Roles
join UserRole in db.UserRoles on Role.ID equals UserRole.RoleID
join user in db.users on UserRole.UserID equals user.id
where UserRole.UserID == UserId
select new { RoleName = Role.RoleName, email = user.email, UserId = user.id }; var userss = query.ToList();
foreach(var userList in userss) { Users.Add(new user() { id = userList.UserId,
email = userList.email,
RoleName = userList.RoleName }); }
LoadRoles(Users);
return View(Users); }
public void LoadRoles(IListmodel)
{ var Roles = db.Roles.AsQueryable().Select(x => new SelectListItem()
{ Text = x.RoleName,
Value = SqlFunctions.StringConvert((double) x.ID)
}).ToList();
var UserModel = new user()
{ Roles = Roles.ToList() }; }
I am able to get other values from the LINQ in the first part of view but unable to populate the dropdownlist.
How can I populate the dropdownlist. I have tried so much but still no luck. Any urgent help will be appreciated.
Joginder BangerPosted Nov 28, 2014, 2:31 AM
if you need populate the Dropdownlist as lot of javascript function available or you can try with the help of CSS. If you are used CSS then the Populate Dropdownlist working as it is.
i share one CSS code just paste in your css and check this link.
download here a full with css.
http://www.smashingmagazine.com/2013/05/22/centering-elements-with-flexbox/
krishna angirekulaPosted Nov 28, 2014, 12:48 AM
Datatext field
datavalue field to assign
For U Required coloums