Ajax.ActionLink替代-网络核心 [英] Ajax.ActionLink Alternative - Net Core

查看:65
本文介绍了Ajax.ActionLink替代-网络核心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MVC 中的早期版本,我使用@Ajax.ActionLink进行Ajax调用,并在布局中替换了容器.

Earlier in MVC I used @Ajax.ActionLink for Ajax call and replaced container in my layout.

现在 .Net Core 中有类似 AjaxHelper 之类的东西.

Now in .Net Core there is anything like AjaxHelper back then.

如何为仪表板中的每个菜单项编写 jquery 脚本而不会形成 Ajax 调用.

How can I form Ajax call without writing jquery script for every menu item in my dashboard.

我尝试了使用匿名 Ajax 参数的@Url.Action,但无法正常工作.

I tried @Url.Action with anonymous Ajax parameters but that won't work.

@Url.Action("Index", "User", new
{
  data_ajax = "true",
  data_ajax_method = "GET",
  data_ajax_mode = "replace",
  data_ajax_update = "#replace"
}))"

推荐答案

否.老实说,您再也不需要它了.它所做的只是创建一个常规链接,然后添加一些琐碎的JavaScript,您可以轻松地添加自己.多头和空头,随它去吧:

No. Honestly, you never needed it anyways. All it did was create a regular link and then add a trivial bit of JavaScript you can easily add yourself. Long and short, let it go:

<a class="menu-item" asp-action="Index" asp-controller="User">Click Me</a>

然后:

<script>
    $('.menu-item').on('click', function (e) {
        e.preventDefault();
        $.get(this.href, function (html) {
            $('#replace').html(html);
        });
    });
</script>

通过绑定到该类,对于与menu-item类的任何链接,您只需要使用这片JS.

By binding to the class, you only need this one piece of JS for any link with a menu-item class.

这篇关于Ajax.ActionLink替代-网络核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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