有没有办法调用一些泛型函数,告诉我下拉列表的值: 我将隐藏这个oldStatusID。 所以,正如你在我的数据库中看到的那样:
JobstatusID |状态名称 4 |展望/等待提案
当我更改状态时,例如“Lost”,然后单击“保存”,程序保持id = 4,而不是id = 2 ..
以下是我的观点:
@using System.Collections.Concurrent
@model DataAccess.PartialClass.StatusPipelineMerge
@{
ViewBag.Title = "Edit";
}
<h2>Edit</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>AdeccoView</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.PipelineID)
@*@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.StatusID)*@
<div class="form-group">
@Html.LabelFor(model => model.ProjectValueMoney, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model=>model.ProjectValueMoney, new { htmlAttributes = new { @class = "form-control" } })
@*@Html.ValidationMessageFor(model => model.ProjectValueMoney, "", new { @class = "text-danger" })*@
</div>
</div>
<div class="form-group">
@Html.LabelFor(model=>model.ProjectValueHr, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ProjectValueHr, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ProjectValueHr, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CommentPipeline, htmlAttributes: new {@class = "control-label col-md-2"})
<div class="col-md-10">
@Html.EditorFor(model => model.CommentPipeline, new {htmlAttributes = new {@class = "form-control"}})
@Html.ValidationMessageFor(model => model.CommentPipeline, "", new {@class = "text-danger"})
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FCOID, htmlAttributes: new {@class = "control-label col-md-2"})
<div class="col-md-10">
@Html.EditorFor(model => model.FCOID, new {htmlAttributes = new {@class = "form-control"}})
@Html.ValidationMessageFor(model => model.FCOID, "", new {@class = "text-danger"})
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.OldStatusId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.OldStatusId, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.OldStatusId, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ClientID, "Client Name", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("ClientID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.ClientID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("Field of Cooperation", new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("FCO", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.FCOName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.Label("Status", new {@class = "control-label col-md-2"})
<div class="col-md-10">
@Html.DropDownList("Status2", null, htmlAttributes: new {@class = "form-control"})
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default"/>
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
这是我的控制器 - 编辑(获取和发布)
//// GET: AdeccoViews/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
StatusPipelineMerge merge1 = new StatusPipelineMerge();
merge1.CommentPipeline = db.Pipelines.Find(id).CommentPipeline;
merge1.ProjectValueHr = db.Pipelines.Find(id).ProjectValueHr;
merge1.ProjectValueMoney = db.Pipelines.Find(id).ProjectValueMoney;
merge1.PipelineID = (int)id;
merge1.JobStatusName = statusOnId(id);
merge1.FCOID = db.Pipelines.Find(id).FCOID;
merge1.oldStatusId = statusIDSelected(id);
// HttpCookie cookie = CookieManager.CreateCookie("MergePipelineStatus", .CreatedBy.ToString(), adeccoView.CreatedTimeStamp.ToString(), id.ToString());
// Response.SetCookie(cookie);
if (merge1 == null)
{
return HttpNotFound();
}
ViewBag.ClientID = new SelectList(db.Clients.OrderBy(x => x.ClientName), "ClientID", "ClientName", merge1.ClientID);
//ViewBag.Comment = new SelectList(db.Pipelines, "CommentPipeline", merge1.CommentPipeline);
ViewBag.Comment = new SelectList(db.Pipelines, "PipelineID", "CommentPipeline", merge1.CommentPipeline);
ViewBag.ProjectValueHR = new SelectList(db.Pipelines, "PipelineID", "ProjectValueHr", merge1.ProjectValueHr);
ViewBag.ProjectValueMoney = new SelectList(db.Pipelines, "PipelineID", "ProjectValueMoney", merge1.ProjectValueMoney);
ViewBag.FCO = new SelectList(db.FCOes, "FCOID", "NameFCO", merge1.FCOName);
ViewBag.Status2 = new SelectList(getJobStatus(statusOnId(id)), "JobStatusID", "JobStatusName", merge1.JobStatusName);
ViewBag.Status3 = new SelectList(getJobStatus(statusOnId(id)), "JobStatusId", "JobStatusName", merge1.StatusID);
ViewBag.OldStatus = new SelectList(getJobStatus(statusOnId(id)), "JobStatusId", "JobStatusId", merge1.OldStatusId);
return View(merge1);
}
//// POST: AdeccoViews/Edit/5
//// To protect from overposting attacks, please enable the specific properties you want to bind to, for
//// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "Status2,Status3,ID,PipelineID,ProjectValueHr,ProjectValueMoney,CommentPipeline,StatusID,JobStatusName,FCOID,ClientID,CreatedTimeStamp,CreatedBy,ModifiedTimeStamp,ModifiedBy")] StatusPipelineMerge merge)
{
if (ModelState.IsValid)
{
string controllerName = "MergePipelineStatus";
Pipeline pipe = new Pipeline();
PipelineJobStatu pjs = new PipelineJobStatu();
pipe.PipelineID = merge.PipelineID;
pipe.ProjectValueHr = merge.ProjectValueHr;
pipe.ProjectValueMoney = merge.ProjectValueMoney;
Employee user1 = Session["User"] as Employee;
pipe.CreatedBy = user1.EmployeeD;
pipe.CommentPipeline = merge.CommentPipeline;
DateTime myDateTime = DateTime.Now;
string sqlFormattedDate = myDateTime.ToString("yyyy-MM-dd HH:mm:ss");
pipe.CreatedTimeStamp = Convert.ToDateTime(sqlFormattedDate);
pipe.ClientID = merge.ClientID;
pipe.FCOID = merge.FCOID;
pjs.PipelineID = merge.PipelineID;
pjs.JobStatusID = merge.StatusID;
pjs.CreatedBy = user1.EmployeeD;
pjs.CreatedTimeStamp = Convert.ToDateTime(sqlFormattedDate);
db.Pipelines.Add(pipe);
db.PipelineJobStatus.Add(pjs);
db.Entry(pipe).State = EntityState.Modified;
db.Entry(pjs).State = EntityState.Modified;
db.SaveChanges();
CookieManager.SetCookie(Consts.COOKIE_NAME, 1, "Upešno izmenjen task", EnumNotificationMessageType.success, Response);
return RedirectToAction("Index");
}
ViewBag.Status2 = new SelectList(getJobStatus(statusOnId(merge.PipelineID)), "JobStatusID", "JobStatusId", merge.JobStatusName);
ViewBag.Status3 = new SelectList(getJobStatus(statusOnId(merge.PipelineID)), "JobStatusId", "JobStatusId", merge.StatusID);
ViewBag.ClientID = new SelectList(db.Clients, "ClientID", "ClientName", merge.ClientID);
//ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeD", "Name", adeccoView.EmployeeID);
//ViewBag.EventTypeID = new SelectList(db.EventTypes, "EventTypeID", "Event", merge.EventTypeID);
return View(merge);
}
所以,我尝试使用Status2 ViewBag,为文本/字符串提取id。 谢谢!