In this articles of ASP.NET MVC we will learn about Dropdown using Model Class and Sql Linq Query so let's start
Firstly create a model class which you want to show data in your dropdown
In my case i create a model called GEN_User
public partial class GEN_Users
{
public long sysUserID { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}
Now go to your controller class and paste a code below:
public ActionResult Index()
{
ViewBag.userName = new SelectList(db.GEN_Users, "sysUserID", "Username");
return View();
}
Go to your view and simply paste a code below:
@Html.DropDownList("GEN_Users", (SelectList)ViewBag.userName, "Select One", new { @class = "form-control "})
Thank you for reading and if you have any query then leave a message.
Comments
Post a Comment