Ajax.ActionLink Alternative - Net Core

前端 未结 1 583
轮回少年
轮回少年 2021-01-24 10:14

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

Now in .Net Core there is anything like Aja

相关标签:
1条回答
  • 2021-01-24 10:55

    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>
    

    Then:

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

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

    0 讨论(0)
提交回复
热议问题