我正在加载项目,它在下拉列表中,但是我要选择的是从该数据库中选择的项目,即在编辑模式下,从该数据库中选择的项目,即ID和名称在下拉菜单中预先选择,但不是。为什么?
public ActionResult Edit(int id)
{
User user = (User)Session["User"];
if (user == null)
{
return RedirectToAction("Login", "Home");
}
UnitOfWork uwork = new UnitOfWork();
InspectionReport InspectionReportUow = uwork.InspectionReportRepository.GetByID(id);
InitialsDAL InitialsDAL = new DAL.InitialsDAL();
ViewBag.ListInitials = InitialsDAL.GetInitialsListFiltered("");
ProjectsDAL ProjectsDAL = new DAL.ProjectsDAL();
TempData["Projects"] = ViewBag.ListProjects = ProjectsDAL.GetProjectsListFiltered("", (user.UserRoleName == "admin" || user.UserRoleName == "Admin" || user.UserRoleName == "Preparator" || user.UserRoleName == "preparator") ? user.Emp_ID : 0);
RemarksHistoryDAL RemarksHistoryDAL= new DAL.RemarksHistoryDAL();
InspectionReportUow.ListRemarksHistory = RemarksHistoryDAL.GetRemarksHistoryByInpecID(id); //id= InspectionReportID
return View(InspectionReportUow);
}
查看:
@model VAILCertificates.DAL.Entities.InspectionReport
@{
ViewBag.Title = "";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Inspection Report Details</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.InspectionReportID)
<div class="form-group">
@Html.Label("Project", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-3">
@Html.DropDownListFor(model => model.ProjectID, new SelectList(ViewBag.ListProjects, "ID", "ProjectNo"),
"-Select-",
new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.ProjectID, "", new { @class = "text-danger" })
</div>
</div>
}