Why is Ajax.BeginForm redirected to a new blank page after submission?

Why does Ajax.BeginForm redirect my page to a new blank page after submission?

My controller code:

    [HttpPost]
    public void ProductCommentAdd(int productId, string text)
    {
           //Do something
    }

Mvc ajax call in view:

    @using (Ajax.BeginForm("ProductCommentAdd", "Shop", new AjaxOptions() { HttpMethod = "POST"}))
    {
                <input type="hidden" value="@Model.ProductId" name="ProductId"/>
                <textarea name="text"></textarea>
                <input type="submit" value="Submit"
    }

When I click the submit button, my page is redirected to a new blank page. How can i fix this?

+4
source share
1 answer

you need to include the following script page in the page:

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" 
                       type="text/javascript"></script>
+10
source

Source: https://habr.com/ru/post/1527009/


All Articles