Request.Url.PathAndQuery
PublicRedirectresult AddToCart (Cart cart,intProductId,stringreturnUrl) {Product Product= This. Productrepository.products. FirstOrDefault (P= = P.productid = =productId); if(NULL!=productId) {cart. AddItem (Product,1); } RETURNURL= This. request["RETURNURL"]; //return redirecttoaction ("Index", new {RETURNURL}); returnRedirect (RETURNURL); }View Code
@model Easy5.ASPMVC.SportsStore.Domain.Entities.Product<divclass="Item"> @Model. Name@Model. Description @using (Html.BeginForm ("AddToCart","Cart")) { /*1. Create a hidden field ProductID*/@Html. hiddenfor (x=X.productid)/*2. Argument: "ReturnUrl" must be the same as the parameter name of the corresponding argument*/ @Html. Hidden ("returnUrl", Request.Url.PathAndQuery)/* Return to the requested address on this page * /<input type="Submit"Value="+ Add to Cart"/> } @Model. price.tostring ("C")
$.ajax
@Url. Action
<TD style="Text-align:center;"> "@Url. Content ("~/images/update.png")"alt="Update"title="Update" class="Updateshoppingcartitembutton"Id="@string. Format ("update_{0}", Item.id)"/> </td> <td style="Text-align:center;"> "@Url. Content ("~/images/delete.png")"alt="Delete"title="Delete" class="Deleteshoppingcartitembutton"Id="@string. Format ("delete_{0}", Item.id)"/> </td>@section scripts{<script type="Text/javascript">function IsNumeric (input) {return(Input-0) = = Input && input.length >0; } $ (function () {$ (". Updateshoppingcartitembutton"). Click (function () {varButtonID = $ ( This). attr ('ID'); varqid = buttonid.replace ('Update_','Quantity_'); varItemID = Buttonid.replace ('Update_',"'); varQuantity = $ ('#'+qid). Val (); varPostURL ='@Url. Action ("Updateshoppingcartitem", "Home")'; varRedirectURL ='@Url. Action ("ShoppingCart", "Home")'; if(!isnumeric (quantity)) {Alert ('The quantity value you enter must be a number. '); return; } varIntquantity =parseint (quantity); if(Intquantity <=0) {alert ('The quantity value entered must be a value greater than or equal to 1. '); Window.location.href=RedirectURL; return; } $.ajax ({type:"POST", Url:posturl, data: {shoppingcartitemid:itemid, quantity:intquantity}, Success:function (msg) {window.location.href=RedirectURL; } }); }); $('. Deleteshoppingcartitembutton'). Click (function () {if(Confirm ('Are you sure you want to delete the selected item? ')) { varButtonID = $ ( This). attr ('ID'); varItemID = Buttonid.replace ('Delete_',"'); varPostURL ='@Url. Action ("Deleteshoppingcartitem", "Home")'; varRedirectURL ='@Url. Action ("ShoppingCart", "Home")'; $.ajax ({type:"POST", Url:posturl, data: {Shoppingcartitemid:itemid}, Success:function (msg) {window.location.href=RedirectURL; } }); } }); }); </script>}View Code