C# Ajax.ActionLink备选方案-Net Core

C# Ajax.ActionLink备选方案-Net Core,c#,ajax,asp.net-core,C#,Ajax,Asp.net Core,在MVC早期,我使用了@Ajax.ActionLink进行Ajax调用,并在布局中替换了容器 现在在.NETCore中有类似于AjaxHelper的东西 如何在不为仪表板中的每个菜单项编写jquery脚本的情况下形成Ajax调用 我用匿名Ajax参数尝试了@Url.Action,但没有用 @Url.Action("Index", "User", new { data_ajax = "true", data_ajax_method = "GET", data_ajax_mode = "

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

现在在.NETCore中有类似于AjaxHelper的东西

如何在不为仪表板中的每个菜单项编写jquery脚本的情况下形成Ajax调用

我用匿名Ajax参数尝试了
@Url.Action
,但没有用

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

不,老实说,你从来都不需要它。它所做的只是创建一个常规链接,然后添加一点JavaScript,您可以轻松添加自己。长短不一,让它去吧:

<a class="menu-item" asp-action="Index" asp-controller="User">Click Me</a>
点击我
然后:


$('.menu item')。在('click',函数(e)上{
e、 预防默认值();
$.get(this.href,函数(html){
$('#replace').html(html);
});
});

通过绑定到类,对于带有
菜单项
类的任何链接,您只需要这一块JS。

您是否错过了JS包?检查对jquery和jquery.unobtrusive-ajax脚本包的引用,我通过nuget安装了它,它没有向wwwroot/js添加任何.js文件,jquery-ajax工作得很好。
<script>
    $('.menu-item').on('click', function (e) {
        e.preventDefault();
        $.get(this.href, function (html) {
            $('#replace').html(html);
        });
    });
</script>