So I'm implementing a small badge in my header indicating how many items the user has in his cart..
This is how I've thought of doing it: Set the badge value on user log in and then just increment/decrement it when the user adds/removes from his cart.
I tried setting the value in jquery on my index page like this:
function loadCartBadgeVal(id) {
$.getJSON(`/Cart/GetCartCount?customerId=${id}`,
function (data) {
$("#cart-badge").text('' + data);
});
}
This works but when I redirect to another page my badge value resets to 0 .. my badge is implemented in a partial view like this:
<span class="badge badge-info" id="cart-badge"></span>