Skip to content

Instantly share code, notes, and snippets.

@troufster
Created April 27, 2011 14:45
Show Gist options
  • Save troufster/944368 to your computer and use it in GitHub Desktop.
Save troufster/944368 to your computer and use it in GitHub Desktop.
"Proper" handling of MVC3 Ajax links
@Html.ActionLink("Click me!", "AjaxStuff", null,
new { id = "ajaxstuff" })
@Ajax.ActionLink("Hurf", "Durf", "Controllurf",
new { param = somestuff },
new AjaxOptions {
HttpMethod = "Post",
OnSuccess = "Somejs"
})
public ActionResult AjaxStuff(object foo) {
var stuff = new { Name = "Stuff" + foo };
ViewBag.Stuff = stuff.Name;
return View();
}
$('#ajaxstuff').ajaxLink({
data: { foo: 'Fooinator' },
success: function (data) {
$('#ajaxdiv').html(data);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment