Как получить доступ к свойству класса, которое я получаю с помощью ajax
in index.cshtml i use ajax in click event of .removelink to get changes from action controller As follows :
$(".RemoveLink").click(function () {<br /> // Get the id from the link<br /> var recordToDelete = $(this).attr("data-id");<br /> if (recordToDelete != '' || recordToDelete != null) {<br /> // Perform the ajax post <br /> $.ajax({<br /> //contentType: 'application/json',<br /> //dataType: 'text',<br /> type: 'post',<br /> dataType: 'JSON',<br /> url: '/ShoppingCart/RemoveFromCart/',<br /> data: { id: recordToDelete },<br /> success: function (data) { <br /> if (data.ItemCount == 0) {<br /> $('#row-' + data.DeleteId).fadeOut('slow');<br /> }<br /> else {<br /> $('#item-count-' + data.DeleteId).text(data.ItemCount);<br /> }<br /> $('#cart-total').text(data.CartTotal);<br /> $('#update-message').text(data.Message);<br /> $('#cart-status').text('Cart (' + data.CartCount + ')');<br /> }<br /> }); <br /> } <br /> });
and in controller:
<pre>//AJAX: /ShoppingCart/RemoveFromCart/5<br /> [HttpPost]<br /> public IActionResult RemoveFromCart(int id)<br /> {<br /> //Remove the item from the cart<br /> var cart = ShoppingCart.GetCart(this.HttpContext);<br /> // Get the name of the album to display confirmation<br /> //string albumName = _context.Carts<br /> //.Single(item => item.RecordId == id).Album.Title;<br /> Cart cartt = ShoppingCart.getCartForGetalbumName(id);<br /> // Remove from cart<br /> int itemCount = cart.RemoveFromCart(id);<br /> // Display the confirmation message<br /> var results = new ShoppingCartRemoveViewModel<br /> {<br /> Message = HtmlEncoder.Default.Encode(cartt.Album.Title) +<br /> " has been removed from your shopping cart.",<br /> CartTotal = cart.GetTotal(),<br /> //CartCount = cart.GetCount(),<br /> ItemCount = itemCount,<br /> DeleteId = id<br /> };<br /> return Json(results); <br /> }</pre>
but it don't work and the text of the tags doesn't change and fadeOut() doesn't work. Please help me to resolve my problem which I have been involved for several days
Что я уже пробовал:
in index.cshtml i use ajax in click event of .removelink to get changes from action controller, but this don't work