【问题标题】:Load my partial view in a specific div at the same page after a click单击后在同一页面的特定 div 中加载我的部分视图
【发布时间】:2014-01-14 20:04:54
【问题描述】:

我有这个代码

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult ManageEmployee(int cntID, string command)
{
    repository = new ContactRepository();
    if (!String.IsNullOrEmpty(command) && command.Equals("edit"))
    {
        LKIContact employees = repository.GetById(cntID);

        ViewBag.IsUpdate = true;
        return PartialView("_ManageEmployee", employees);
    }
    else
    {
        ViewBag.IsUpdate = false;
        return PartialView("_ManageEmployee");
    }
}

当我点击时:

<a href='Home/ManageEmployee?cntID=${cntID}&command=edit' class='editDialog'>Edit</a>

我执行上述方法的第一部分以显示我填充的表单以进行更新 当我点击href='Home/ManageEmployee?cntID=0&amp;command=create' class='openDialog' 时,我会打开空表单来添加新员工。

我现在的问题是,当我点击编辑或创建时,我得到了想要的结果,但在另一个页面中。我想要的是在特定的 div 中滑出这些表单(如下),同时保持在同一页面上。(在网格下)

<div id="dialog-edit"></div>
<div id="dialog-create" style="display: none"></div>

这里是我的网格将被加载的代码以及我希望我的表单被加载的 div 的位置

@section featured {
<section class="featured">
    <div class="content-wrapper">
        <!-- the igHierarchicalGrid target element-->
        <table id="employeeGrid" style="width: auto;"></table>
        <p>
            <!--<a id='openDialog' href='Home/CreateEmployee?cntID=0' class='openDialog ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' style="color: white;"><button>Add Employee</button></a>-->
       </p>
    </div>
</section>

<br />
<div id="dialog-confirm" style="display: none">
    <p>
        <span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
            Are you sure to delete ?
    </p>
</div>

<div id="dialog-edit"></div>

<div id="dialog-view" style="display: none"></div>

}

感谢您的帮助

【问题讨论】:

标签: c# jquery asp.net asp.net-mvc razor


【解决方案1】:

您可以使用 ajax 调用来获取部分视图并将其呈现在您的 div 中:

<script type="text/javascript">
  $(document).on("click", "#btnEdit", function () {

        $.ajax({
            url: "Home/ManageEmployee?cntID=" + myEmployeeID + "&command=edit";
            cache: false,
            success: function (html) {
                $("#dialog-edit").append(html);
            }
        });

    });
</script>

在页面底部添加此脚本,将 btnEdit 替换为您的编辑按钮的 ID,并将 MyEmployeeID 替换为您要编辑的员工 ID。

【讨论】:

  • 您提到网格的每一行都有编辑按钮。您可以发布网格的标记吗?您可以编辑您的问题并向其附加代码。
  • 抱歉,我的回答对 igGrid 帮助不大。
【解决方案2】:

如果您对每一行都有一个编辑按钮,您可以在链接标签中包含 EmployeeId,可能作为数据属性这样

<a href='Home/ManageEmployee?cntID=${cntID}&command=edit' data-employeeid='${cntID}' class='editor'><button>Edit</botton></a>

然后使用来自 afzalulh 的示例,只需选择数据属性

<script type="text/javascript">
  $(document).on("click", ".editor", function () {

        var myEmployeeID = $(this).data('employeeid');

        $.ajax({
            url: "Home/ManageEmployee?cntID=" + myEmployeeID + "&command=edit";
            cache: false,
            success: function (html) {
                $("#dialog-edit").append(html);
            }
        });

    });
</script>

【讨论】:

  • 感谢您的帮助,但遗憾的是没有得到所需的结果
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多