views:

67

answers:

1

This is a followup question to the one I posted last week "Ajax.ActionLink not Posting". I did finally get it to Post, and it properly calls my Delete action and deletes the record. The Delete method returns a RedirectToAction("List") so that the new data set minus the deleted record is re-listed. Except that what actually happens is - NOTHING. The listing doesn't change. And I'm pretty sure I know why: calling Ajax.ActionLink returns an Ajax result which is only supposed to replace a designated element (the UpdateTargetId option parameter) in the document. And since I haven't designated any, it doesn't replace anything, even though it's a whole fresh page.

My question is, what do I pass to the AjaxOption.UpdateTargetId to get it to wipe the whole page and reload with the new result, just as though Html.ActionLink had been called (recalling that the only reason for using Ajax.ActionLink was that I wanted the method invoked with a POST instead of a GET)? (And since this page uses a Master Page, I don't have the option of just putting an ID on the body element.)

A: 

You can do a POST without Ajax. You would need to use a Form and change your ActionLink to a Submit button. That might be the simplest way.

Otherwise, you need to change your List action to return a PartialView. This is what renders to your UpdateTargetId, which you can just set as an outer div on your page.

Do you really need to reload your list at all? You can do your Ajax POST to delete the row in the database, and use the OnSuccess property of the AjaxOptions to call a JavaScript function which then removes the row from the html on the page.

fearofawhackplanet
Well, you probably make a good point. I do know how to POST using <form action=URL method=POST>, but I didn't want to use that because there are other functions being performed by the form submit operation. But maybe I need to rethink that.What I really wanted was something that performed just like Html.ActionLink, but did a POST instead of a GET. I tried making an anchor tag with an onclick=javascript:$.post(/controller/action), but I couldn't get that to work, and couldn't figure out why.
Dave Hanna
To close the loop, I took your advice: I created a ListPartial partial view out of just the data grid part of my List view, and called that from the List view itself, enclosing it in a div. Then I made the Delete action construct all the data for a List view, and made my Delete View contain nothing more than a RenderPartial of ListPartial. Now in my Ajax.ActionLink, I can use the ID of the div that contains the partial as the UpdateTargetID, and when the Delete finishes, its output (replaces that).Thanks for your help.
Dave Hanna