Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I am new to mvc i want to fill and display a drop down list.But the problem is i am having two tables naming Team and Users.The team that is inserted should be displayed as a dropdown in users screen.I have tried different types but in vain...Can someone help me plzz

Thanks,
Maruthi Ram.

C#
public class Team
   {
       public int TeamId { get; set; }
       public String TeamName { get; set; }
       public int TeamSize { get; set; }
   }


SQL
public class Users
   {

       public int UserId { get; set; }

       public int TeamId { get; set; }

       public String UserName { get; set; }

       public DateTime DateofBirth { get; set; }

       public bool ActiveYN { get; set; }

       public bool DeletedYN { get; set; }

       public bool DOBNotificationAccepted { get; set; }

       public DateTime CreatedOn { get; set; }

       public DateTime LastUpdatedOn { get; set; }

       public int CreatedBy { get; set; }

       public int LastUpdatedBy { get; set; }

   }


These are the two classes...
Posted
Updated 3-Feb-14 17:27pm
v2

1 solution

Let me attempt...

One way is to to pass in all of your objects as the "model". Ideally use a ViewModel which will contain the list of all properties and then bind that to your view. This is implementation of the MVVM pattern.

Else, since it looks like a light-weight thing that you are trying to do, simply send a selectlist through a viewbag in controller. Such as...

View:
<label for="Team">Team</label>
   @Html.DropDownListFor("SelectedItem", ViewBag.ListOfTeams)


Controller:
public ActionResult GetTeams()
{
    ViewBag.ListOfTeams = GetTeam();
    return View();
}
 
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