我不知道什么是错的。 我遵循此链接http://www.dotnetcodesg.com/Article/UploadFile/2/286/CRUD%20operation%20using%20Modal%20Popup%20in%20ASP.NET%20MVC%204.aspx因为需要完全相同的东西:带有弹出窗口的CRUD网格进行编辑。
我在VS2013生成的HomeController和Index.cshtml中做了所有事情。
我从代码中删除了所涉及的内容:
Index.cshtml
grid.Column("", header: "Actions",
format: @<text>
@Html.ActionLink("Edit", "EditConstruct", new { id = item.Id, @class = "editDialog" })
<div id="dialog-edit" style="display: none">
控制器
public ActionResult EditConstruct(int id)
{
var data = advConstructRepository.Get(id);
AdvConstructModel model = new AdvConstructModel
{
Id = data.Id,
Description = data.Description,
MaintenanceTime = data.MaintenanceTime,
Location = data.Location,
Height = data.Height,
Width = data.Width,
MonthlyCost = data.MonthlyCost,
AdvConstructType = advConstructRepository.GetAdvConstructType(data.AdvTypeId)
};
ViewBag.IsUpdate = true;
return View("EditConstruct", model);
}
修改视图
@model AdvApplication.Models.AdvConstructModel
@{
Layout = null;
}
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
@using (Html.BeginForm("UpdateConstruct", "Home", "POST"))
{
@Html.ValidationSummary(true)
ViewBag.IsUpdate = true;
return View("EditConstruct", model);
}
etc...
但是当我点击编辑动作时,我会收到要编辑的字段但不会显示在弹出窗口中,而是作为单个页面在整个屏幕上显示。 EditConstruct视图已创建为部分视图。
请建议如何修复
答案 0 :(得分:0)
可能是整个视图被发回,jquery处理片段,而不是整页。
考虑这一变化:
public ActionResult EditConstruct(int id)
{
var data = advConstructRepository.Get(id);
AdvConstructModel model = new AdvConstructModel
{
Id = data.Id,
Description = data.Description,
MaintenanceTime = data.MaintenanceTime,
Location = data.Location,
Height = data.Height,
Width = data.Width,
MonthlyCost = data.MonthlyCost,
AdvConstructType = advConstructRepository.GetAdvConstructType(data.AdvTypeId)
};
ViewBag.IsUpdate = true;
if(Request.IsAjaxRequest())
return PartialView("EditConstruct", model);
return View("EditConstruct", model);
}