我有一个名为Result的模型。假设它有4个字段,例如student_id、marks、status和remarks。
现在我有一个视图,在该视图中显示了学生列表。在每个学生前面,都有一个按钮用于输入考试成绩。单击该按钮后,将弹出一个窗口,其中包含2个字段:学生ID、成绩和2个按钮“通过”和“不通过”。
当点击“不通过”按钮时,会出现另一个弹窗,只用于输入备注信息。
现在我的问题是,如何在第二个弹框中保留第一个弹框的值,在单击第二个弹出窗口的“提交”按钮时,我将保存所有详细信息。
我知道可以使用第二个弹出窗口中的隐藏字段来完成此操作。还有其他方法吗?
模型类如下:
1.用户(id、姓名、父亲名字、地址...)
2.结果(学生ID、成绩、等级、备注)
学生列表视图
@{
List<User> Student = (List<User>)ViewData["Student"];
}
<table id="table_id">
<tr>
<th class="dbtc">S.No.</th>
<th class="dbtc">Student Name)</th>
<th style="width: 110px">Operate</th>
</tr>
@foreach (User usr in Student)
{
int index = Student.IndexOf(usr);
<tr>
<td class="dbtc">
@(Student.ToList().IndexOf(usr) + 1)
</td>
<td>
@Html.ActionLink(usr.FirstName + " " + usr.LastName, "Details", "User", new { id = usr.Id }, null)
</td>
<td>
@Ajax.ActionLink("Examine", "Result", new { id = Model.Id, userId = usr.Id }, new AjaxOptions
{
HttpMethod = "GET",
UpdateTargetId = "divPopup",
InsertionMode = InsertionMode.Replace,
OnSuccess = "openPopup('Examine Content')"
})
</td>
</tr>
考试的第一个部分视图
@model ComiValve.Models.Result
@using (Html.BeginForm("ExamPass", "Student", new { @id = (int)ViewBag.id, userId = (int)ViewData["UserId"] }, FormMethod.Post))
{
<div id="divExamAdvice"></div>
<div class="editor-label">
@Html.DisplayNameFor(model => model.Name)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.Marks)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.Grade)
</div>
<div class="login_submit_div">
<input type="submit" value="Pass" />
@Ajax.ActionLink("Fail", "ExamAdvice", new { id = (int)ViewBag.id, userId = (int)ViewData["UserId"] }, new AjaxOptions
{
HttpMethod = "GET",
UpdateTargetId = "divPopup",
OnSuccess = "openPopup('Exam Advice')"
})
</div>
}
备注的第二个部分视图(当用户点击“失败”时,此视图将打开。)
@model ComiValve.Models.ExamContent
@using (Html.BeginForm("ExamFail", "Student", new { id = Model.id }, FormMethod.Post))
{
<div id="divExamAdvice"></div>
<div class="editor-label">
@Html.DisplayNameFor(model => model.Remarks)
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.Remarks)
</div>
<div class="left">
<input type="submit" value="Confirm Fail" />
</div>
}
控制器的方法
public virtual ActionResult ExamContent(int id, int userId)
{
ViewBag.IsApprove = true;
ViewBag.UserId = userId;
ViewBag.id = id;
return PartialView("ExamContent");
}
public virtual ActionResult ExamAdvice(int id, int userId)
{
ViewBag.IsApprove = true;
if (Request.IsAjaxRequest())
{
Result result = new Result();
result.id = id;
result.User = db.Users.Find(userId);
return PartialView("ExamAdvice", result);
}
else
{
return RedirectToAction("Index");
}
}