ASP.NET MVC Filtering results in a list/grid

前端 未结 6 1872
我寻月下人不归
我寻月下人不归 2020-12-28 21:32

For some reason I\'m stuck on this. I need to filter results from a View based on a DropDownList in the same view. The basic idea is this: I have a list of providers that be

6条回答
  •  别那么骄傲
    2020-12-28 22:25

    To add upon the earlier answers.

    To create a drop down (in ASP .NET MVC 3) I did the following:

    Add code to Index.cshtml

    @using (Html.BeginForm())
    {      
    @Html.DropDownList("EmployeeId", (SelectList)ViewData["EmployeeId"])     
      
    }
    

    Add code to YourModelNameController.cs in the default ActionResult for Index()

    public ActionResult Index()
    {
    
        //create a selectlist
            var employeeList = from el in db.Employee select el;
            ViewData["EmployeeId"] = new SelectList(employeeList, "EmployeeId", "TmName");
    
            return View(modelName);
        }
    

提交回复
热议问题