Code for "asp.net--assorted"

Source: Internet
Author: User

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

&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.