我是MVC 3的新手,Linq to SQL,我试图通过从下拉列表中选择的数据值来填充我的WebGrid但是可以正确使用它。帮助
代码:
控制器:
public class HomeController : Controller
{
EmployeeAtdDataContext DataContext = new EmployeeAtdDataContext();
public ActionResult Index()
{
ViewBag.Message = "Precise Technology Consultants";
//var EmployeeAtd = DataContext.GetAttendance_Sp();
IEnumerable<GetAtdRecord_SpResult> EmployeeAtd = DataContext.GetAtdRecord_Sp(null).ToList();
var names = (from n in DataContext.EmployeeAtds select n).Distinct();
ViewData["EmplID"] = new SelectList(names, "EmplID", "EmplName");
return View(EmployeeAtd);
}
查看:
@using EmployeeAttendance_app.Models
@Html.DropDownList("EmplID")
@{
var grid = new WebGrid(ViewData.Model, defaultSort: "EmplID");
}
@grid.GetHtml()
现在View显示了一个带有名称的填充下拉列表,但我希望当我从列表中单击任何名称而不是webgrid应该为该特定人员加载记录时,为此我写了一个基于empID加载的工作查询,到目前为止,我传递的是NULL,但想通过下拉列表选择加载