I'm looping through a collection on my model using Razor to display it. As an example:

@foreach(var item in myCollection)
{
    <span id='item-@item.Id'>@item.Quantity</span>
    <button type='button' onclick='updateQuantity(@item.Quantity+1);'>Add One</button>
}

In this example, updateQuantity performs an AJAX request, gets the new quantity back, and updates item-@item.Id with the new quantity. However, because @item.Quantity is pulled from the model (passed in via the page's GET method, @item.Quantity is never updated with the new value until the page is reloaded.

My question is: How can I make sure I'm always using the latest value, without having to reload the page?

Related posts

Recent Viewed