ASP.NET Core and JQuery unobtrusive AJAX not working

前端 未结 2 953
别那么骄傲
别那么骄傲 2021-02-04 12:19

If I start a new project in .net 4.5 and hit manage nuget packages, search for ajax, then hit install for ajax unobtrusive. I can then go into my cshtml file and type @Ajax.___

相关标签:
2条回答
  • 2021-02-04 13:04

    While the Ajax.BeginForm() methods do not work, the actual unobtrusive Ajax html does. The C# methods just help generate the Html form tags. Forgive me in thse syntax is wrong, this is from memory, but you get the idea

    @using (Ajax.BeginForm("EmployeeMaster", "Home", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "divEmp" }))
    {
        //form content
    }
    

    becomes

    <form asp-action="EmployeeMaster" asp-controller="Home" method="POST" data-ajax="true" data-ajax-update="divEmp">
        <!-- form content-->
    </form>
    

    NOTE: The above HTML STILL needs the unobtrusive ajax js files for it to wire up these data-* attributes correctly. This is not a part of ASP.NET Core MVC

    0 讨论(0)
  • 2021-02-04 13:19

    What is the equlivalent of OnSuccess

    @using (Ajax.BeginForm("EmployeeMaster", "Home", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "divEmp", OnSuccess="ShowMessage" }))
    {
        //form content
    }
    
    0 讨论(0)
提交回复
热议问题