How to bind dropdown with Database?

Total Post:110

Points:774
C#
 629  View(s)
Ratings:
Rate this:
I am having problem in  binding data in dropdown with Database. Please help me. 
  1. Post:52

    Points:366
    Re: How to bind dropdown with Database?

    In the controller

       public ActionResult Index()
            {
                //get data from data base
                ViewBag.Users =Uow.EmpDetail.SelectAll();      
               
                return View();
            }
     

    In the view

    <fieldset>
                                 
                    <legend><strong>Student Info:</strong></legend>
                    @Html.HiddenFor(x=> x.Id)
                    Name: @Html.TextAreaFor(x=> x.SName, new { maxlength = "10", style = "width:200px;text-align:center" })<br>
                    Class: @Html.TextBoxFor(x=> x.Class)<br>
                    Address:@Html.TextBoxFor(x=> x.Address)<br />
                    Employee :@Html.DropDownListFor(x=> x.Id,
                   new SelectList(ViewBag.ListItem, "Value", "Text"))
                    <input type="submit" value="Submit" />
     
                </fieldset>


    Hope this helps you..



      Modified On Apr-11-2018 10:45:02 PM

Answer