I have an Ajax.Action link hooked up to a post method in my controller class that returns a ContentResult. I’m able to make the request and get the response just fine when looking in a tool like firebug, but I’m having problems trying to actually access or do anything with the response text.
Basically, I have something like this in my controller:
public ContentResult RevertToDefault(int id, string default) { /** Update the DB **/ return Content(default); }
And this in my view:
<%= Ajax.ActionLink( 'Revert', 'RevertToDefault', new { id = Model.MyObject.ID, default = Model.MyObject.DefaultValue }, new AjaxOptions { OnComplete = 'function(r) { alert(r); }' })%>
Right now, the alert just returns [object Object]. The change is made in the database, and I’m guessing that I have access to the ContentResult somewhere in that r object, but I’m having a hard time finding good examples/documentation online.
Any ideas?
Yes, the previous answer is absolutely correct. Just do this: