Search code examples
asp.net-core.net-coreasp.net-core-mvcunobtrusive-ajax

data-ajax-update and data-ajax-mode="replace" not working in dotnet core jquery unobtrusive ajax


I have an anchor which should replace a grid with a partial view .

<a class="btn btn-primary" 
                        data-ajax="true" 
                        data-ajax-method="GET"
                        data-ajax-mode="replace"
                        data-ajax-update="content"
                        data-ajax-url="@Url.Action("add","user")"> Create User </a>
 <div class="row table-area">
    <div class="col-md-12" id="content">
        @Html.AjaxGrid(Url.Action("results", "user"))
    </div>
</div>

I see it calls the user action with partial view but it never updates the section with id="content".

Here is my controller method -

    [Route("add")]
    public IActionResult AddUser()
    {
        return PartialView("Partials/AddUser",new RegisterViewModel());
    }

Ideally it should replace the grid content with the partial view altogether but it is not replacing . The response status is 200 and I can see that the contents are being returned in response . Anybody has any idea what is the issue here ?


Solution

  • Change data-ajax-update="content" to data-ajax-update="#content"