【发布时间】:2014-09-17 10:46:19
【问题描述】:
我的表单上有一个 WebGrid,其中一列的 ActionLink 为:
Html.ActionLink((string)item.Name, "Edit", new { id = item.Id })
以下代码的目的是将编辑屏幕显示为模态弹出窗口并成功发布更新的对象。
控制器 - 获取:
public ActionResult Edit(int id)
{
... //Fetch employeeViewModel @id
TempData["StateData"] = employeeViewModel ;
TempData["ViewState"] = "Edit";
return RedirectToAction("Index");
}
Index.cshtml:
@if (TempData.ContainsKey("ViewState") && TempData["ViewState"].ToString() == "Edit")
{
EmployeeViewModel employeeViewModel = (employeeViewModel)TempData["StateData"];
@Html.Partial("_EditEmployee", employeeViewModel)
<script language="javascript">
$(window).load(function() {
$('#editEmployeeModal').modal('show');
});
</script>
}
编辑表格:
<div class="modal fade" id="editEmployeeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
...
使用完整的 Get/Post 模型进行编辑,所有这些都可以正常工作。 但是,我担心我在 Controller-Get 方法中进行的额外行程:
return RedirectToAction("Index");
谁能指导一下更好的方法?
谢谢!
【问题讨论】:
标签: asp.net-mvc-5