Fraz Sundal
Fraz Sundal

Reputation: 10448

how to update specific div data through ajax in asp.net mvc

how to update specific div data through ajax in asp.net mvc

Upvotes: 2

Views: 6479

Answers (2)

griegs
griegs

Reputation: 22770

Another way might be to return a partil view from your controller and place the resultant html into the div.

    public ActionResult jQueryTagFilter(string filterBy)
    {
      //Do stuff
      return PartialView("TagList", tags);
    }

Then in your html;

    $.post("/Admin/jQueryTagFilter", { filterBy: filter }, function(newUserListHTML) {
        $("#divTags").fadeOut(300, function() {
          $"#divTags").innerHTML = newUserListHTML;
          });

        $("#divTags").fadeIn(300);
    });

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1039508

You may take a look at the UpdateTargetId property:

Controller:

public ActionResult SomeAction()
{
    // you could return a PartialView here if you need more complex HTML fragment
    return Content("<span>some content</span>", "text/html");
}

View:

<div id="result"></div>
<%= Ajax.ActionLink(
    "Update div test", 
    "SomeAction", 
    new AjaxOptions { UpdateTargetId = "result" }
) %>

Upvotes: 3

Related Questions