如何在单击Html.ActionLink时加载部分视图? [英] How to load partial view on clicking Html.ActionLink?

查看:61
本文介绍了如何在单击Html.ActionLink时加载部分视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我单击 Html.ActionLink 时如何在同一页面中加载 PartialView .我在下面列出了我的要求.

Can someone please tell me on how to load PartialView in the same page when clicking on Html.ActionLink. I have listed down my requirements below.

  1. 我有一个Index页面,该页面将列出Employee表中的雇员,并且表中的每一行都具有Edit&删除链接(Html.ActionLink)以更新/删除员工信息.
  2. 此外,索引页面将具有部分视图,其中包含用于创建新员工(或)编辑现有员工的文本框.
  3. 当用户从表中选择编辑"链接时,必须在局部视图的文本框中加载适当的用户详细信息以更新员工详细信息.
  4. 此外,在部分视图中输入的新员工详细信息应存储在数据库表中,同时应将其添加到索引"页面的表中.

以上所有步骤都应在MVC5中不使用Ajax的情况下处理.谁能帮我实现上述步骤?非常感谢您的帮助

All the above steps should handle without using Ajax in MVC5. Can anyone please help me to achieve the above steps? Your help is much appreciated

推荐答案

渲染视图后,加载局部视图的唯一方法是通过Ajax调用,该调用将局部视图返回给您的JQuery/Javascript,然后更新DOM

Once your view is rendered the only way to load a partial view is via an Ajax call which returns the partial view to your JQuery/Javascript and then updates the DOM accordingly.

例如:

您的HTML

<a href="#" id="loadViewButton">Load view</a>
<div id="partialViewContainer"><!-- your partial view will be loaded in here --></div>

您的JQuery:

$('#loadViewButton').on('click', function() {
    $.ajax({
        type: "GET"
        url: '/YourController/YourAction',
        success: function (data, textStatus, jqXHR) {
            $('#partialViewContainer').html(data);
        }
    });
});

您的控制器操作:

[HttpGet]
public ActionResult YourAction()
{
  return View("YourView");
}

这篇关于如何在单击Html.ActionLink时加载部分视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆