我可以查看任何人的记录,然后可以修改它,如果我请单击下面的记录编辑按钮,点击它带你到另一个网页,其中显示文本框和下拉菜单,复选框,编辑和后所有文本框包含值是EmpID
,但问题是,我想在下拉列表中选择前值,喜欢的话应该选择相应的值预选喜欢我的文本框每个用户。填充从数据库使用MVC 3下拉,LINQ to SQL的
我使用LINQ到SQL,ASP.NET MVC 3和C#
代码:
@using EmployeeAttendance_app.Models
@model IEnumerable<GetEmployeeEditDetails_SpResult>
@{
var Item = Model.FirstOrDefault();
}
<style type="text/css">
</style>
<div>
@using (Html.BeginForm("EditEmployee", "Home", FormMethod.Get))
{
<label id="lblName" class="editEmp_label">Name</label>
<input type="text" value= @Item.EmplName name="EmpName" placeholder="Update Name" />
<br />
<label id="lblDept" class="editEmp_label">Department</label>
@Html.DropDownList("DeptID", @Item.DeptName)
<br />
<label id="lblShift" class="editEmp_label">Shift</label>
@Html.DropDownList("ShiftId")
控制器:
public ActionResult EditEmployee()
{
if (!String.IsNullOrEmpty(Session["Admin"] as string))
{
int? EmplId = Convert.ToInt32(Session["EmpEdit"]);
IEnumerable<GetEmployeeEditDetails_SpResult> EmployeeValues = DataContext.GetEmployeeEditDetails_Sp(EmplId).ToList();
var DepNames = (from n in DataContext.HrDepts select new { n.DeptID, n.DeptName }).Distinct();
ViewData["DeptID"] = new SelectList(DepNames, "DeptID", "DeptName");
var ShiftNames = (from n in DataContext.AtdShifts select new { n.ShiftId, n.ShiftName }).Distinct();
ViewData["ShiftId"] = new SelectList(ShiftNames, "ShiftId", "ShiftName");
return View(EmployeeValues);
}
}
这个答案可能会帮助你http://stackoverflow.com/questions/22017613/how-to-pass-id-to-default-value-of-another-view – Shyju
没有先生它没有 – PreciseTech