Why Ajax.BeginForm redirect to new empty page after submission?

前端 未结 2 1675
一向
一向 2021-01-18 14:47

Why Ajax.BeginForm redirect my page to new empty page after submission?

My controller code is:

    [HttpPost]
    public void ProductCommentAdd(int p         


        
相关标签:
2条回答
  • 2021-01-18 14:58

    you need to include the following script to your page:

    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" 
                           type="text/javascript"></script>
    
    0 讨论(0)
  • 2021-01-18 15:12

    As @Mat J and @user3206982 suggests: you probably need the unobtrusive.ajax.js file.

    You can download the package from nuget and add it in the bundles config:

    bundles.Add(new ScriptBundle("~/bundles/jqueryunobtrusive").Include(
            "~/Scripts/jquery.unobtrusive*"));
    

    and in the html:

    @Scripts.Render("~/bundles/jqueryunobtrusive")
    

    Source: https://dotnetthoughts.net/mvc5-ajax-form-is-not-updating-div-but-replacing-the-whole-page-instead/

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