Jquery对话框弹出显示在同一窗口

jquery dialog popup shown in the same window

本文关键字:窗口 显示 对话框 Jquery      更新时间:2023-09-26

我不知道怎么了。我遵循这个链接http://www.dotnetcodesg.com/Article/UploadFile/2/286/CRUD%20operation%20using%20Modal%20Popup%20in%20ASP.NET%20MVC%204.aspx,因为需要非常相同的东西:CRUD网格与弹出的编辑。

我在HomeController和Index中做所有事情。

我从代码中删除了相关的内容:

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视图被创建为分部视图。

请建议如何修复

这可能是整个视图被发回,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);
}