how to update specific div data through ajax in asp.net mvc
+3
A:
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" }
) %>
Darin Dimitrov
2010-05-26 09:01:34
can you please provide an example
Fraz Sundal
2010-05-26 09:03:01
@Fraz, I've added an example.
Darin Dimitrov
2010-05-26 09:18:08
A:
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);
});
griegs
2010-05-27 00:39:31