137
rated 0 times
[
143]
[
6]
/ answers: 1 / hits: 35098
/ 10 Years ago, thu, august 14, 2014, 12:00:00
I want to display notifications whenever a user click on the Add to Cart button using the Toastr plugin. Basically, when a user click on the button, it executes the action AddToCart then redirects to the index page. When the page shows up, it checks the TempData value, then shows the notification.
This is the controller:
public ActionResult AddToCart(int id)
{
TempData[message] = Added;
return RedirectToAction(Index);
}
and the view:
@if (TempData[message] != null)
{
<script type=text/javascript>
$(document).ready(function () {
toastr.success('Added')
})
</script>
}
Update
it worked according to @Exception's answer. However, if I use ajax such as:
@Ajax.ActionLink(Add to cart, AddToCart, Home, new { id = item.ProductId }, new AjaxOptions { UpdateTargetId=abc})
it doesnt work. That may be because of the line:
$(document).ready(function ()
as the page is not reloaded.
How can I fix it?
But this doesnt work.
Please help. Thanks in advance!
More From » jquery