Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating the whole page with an Ajax.ActionLink

Is it possible to have an Ajax.ActionLink(...,...) to refresh the whole page instead of an UpdatetargetID?

I prefer using an Ajax.ActionLink because the classic Html.ActionLink is not a POST method.

I try:

@Ajax.ActionLink("Click me", "MyAction", "MyController", new { value = '1234' }, new AjaxOptions { HttpMethod = "POST", Confirm = "Are you sure ?" },  null) 

But the page is not refreshed, I had to press F5.

Thanks.

like image 797
Bronzato Avatar asked Nov 29 '12 17:11

Bronzato


1 Answers

You can actually combine the two methods proposed by gardarvalur to get MVC-like code that doesn't require wrapping the entire page in a div. Move window.location.reload() call to the OnSuccess property of the AjaxOptions object like this:

@Ajax.ActionLink("Click me", "MyAction", "MyController", new { value = '1234' }, new AjaxOptions { HttpMethod = "POST", OnSuccess="window.location.reload()" })

No jQuery involved, just some plain old javascript in an MVC Ajax ActionLink.

like image 103
Corin Avatar answered Nov 15 '22 03:11

Corin