I have an ActionLink in my view. When clicked, an action in my controller is fired (I placed a breakpoint to check). It works only the first time the link is clicked. Other times, the breakpoint in my action controller is never reached.
@Ajax.ActionLink("Remove image", "RemoveImage", new { projectID = Model.ProjectID }, new AjaxOptions { OnSuccess="ImageRemovedSuccess" })
The function "ImageRemovedSuccess" for the OnSuccess ajax event is well fired but the action in the controller is not fired.
Any suggestions?
Thanks.
Your browser caches the response. So the second time when you send the request browser will not forward it to the server because the same request was sent to the server before and the browser will return the cached response to the page.
Decorate the action method not to cache the response in between.
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult RemoveImage(int projectID)
{
}
Make sure you press "Ctrl + F5" on the browser before you check it.
Partial views don't like the settings NoStore
or a Duration
of 0.
You get Additional information: OutputCacheAttribute for child actions only supports Duration, VaryByCustom, and VaryByParam values. Please do not set CacheProfile, Location, NoStore, SqlDependency, VaryByContentEncoding, or VaryByHeader values for child actions.
for NoStore
and another error that Duration must be positive
if you set Duration=0
The fix for Partial views (compatible with the normal views) is:
[OutputCache(Duration = 1, VaryByParam = "*")]
This caches for a maximum of one second, which should be fine for normal operations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With