2
It is possible to force updating some values of my View even when using the window.history.back()
of Javascript? My example:
In my layout, I have a cart icon with the number of items inside it. When I add an item to the cart with this code:
function AddCartItem(obj) {
obj.SelectedResolutionID = $('input[name=ImageResolutionID]:checked').val();
$.ajax({
method: "POST",
url: "/Ajax/AddCart",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json"
})
.done(function (obj) {
if (obj.response) {
setTimeout(function () { window.history.back() }, 500);
}
});
}
and return to the previous page using window.history.back()
as written in the above code. However, this command may cache the previous page, and the icon with the number of items does not update ! it is possible for me to force this update and keep the command window.history.back()
?
I use ASP.NET MVC5, the number of items in my basket comes from a cookie control class, follows the code:
<li>@CartCookieController.ReturnCartProductsCount()</li>
You can do this by creating a client-side storage form, such as localStorage and calling a JS function that will update the number on the cart icon whenever a page opens, either by
history.back()
or not.– Sam