【Asp.Net-- 雜七雜八】的代碼

來源:互聯網
上載者:User

標籤:des   style   class   blog   code   java   

 

Request.Url.PathAndQuery
        public RedirectResult AddToCart(Cart cart, int productId, string returnUrl)        {            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 });            return Redirect(returnUrl);        }
View Code
@model Easy5.ASPMVC.SportsStore.Domain.Entities.Product<div class="item">    <h3>        @Model.Name    </h3>    @Model.Description        @using(Html.BeginForm("AddToCart", "Cart"))    {        /*  1.建立一個隱藏的欄位ProductID         */        @Html.HiddenFor(x=>x.ProductID)       /*  2.實參:"returnUrl" 必須與對應的參數的參數名名一樣        */        @Html.Hidden("returnUrl", Request.Url.PathAndQuery)/*返回本頁面的請求地址*/        <input type="submit" value="+ 加入購物車"/>    }    <h4>        @Model.Price.ToString("c")    </h4></div>

 

        $.ajax       

 

@Url.Action

 

                        <td style="text-align: center;">                            <img src="@Url.Content("~/Images/Update.png")" alt="更新" title="更新" class="UpdateShoppingCartItemButton" id="@string.Format("update_{0}", item.ID)" />                        </td>                        <td style="text-align: center;">                            <img src="@Url.Content("~/Images/Delete.png")" alt="刪除" title="刪除" 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 () {                var buttonID = $(this).attr(‘id‘);                var qid = buttonID.replace(‘update_‘, ‘quantity_‘);                var itemID = buttonID.replace(‘update_‘, ‘‘);                var quantity = $(‘#‘ + qid).val();                var postUrl = ‘@Url.Action("UpdateShoppingCartItem", "Home")‘;                var redirectUrl = ‘@Url.Action("ShoppingCart", "Home")‘;                if (!IsNumeric(quantity)) {                    alert(‘輸入的數量值必須是數值。‘);                    return;                }                var intQuantity = parseInt(quantity);                if (intQuantity <= 0) {                    alert(‘輸入的數量值必須是大於或等於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(‘是否確定要刪除所選商品?‘)) {                    var buttonID = $(this).attr(‘id‘);                    var itemID = buttonID.replace(‘delete_‘, ‘‘);                    var postUrl = ‘@Url.Action("DeleteShoppingCartItem", "Home")‘;                    var redirectUrl = ‘@Url.Action("ShoppingCart", "Home")‘;                    $.ajax({                        type: "POST",                        url: postUrl,                        data: { shoppingCartItemID: itemID },                        success: function (msg) {                            window.location.href = redirectUrl;                        }                    });                }            });        });    </script>}
View Code

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.