4

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 ?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Joy
  • 6,438
  • 8
  • 44
  • 75

2 Answers2

9

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

Scott Baker
  • 10,013
  • 17
  • 56
  • 102
Nick Turner
  • 927
  • 1
  • 11
  • 21
1

Rather than using data-ajax-url, use the asp-controller and asp-action and the #content should work.

<a class="btn btn-primary" asp-controller="user" asp-action="add" 
                        data-ajax="true" 
                        data-ajax-method="GET"
                        data-ajax-mode="replace"
                        data-ajax-update="#content">Create User</a>
D. Dahlberg
  • 156
  • 1
  • 9