• 【Asp.Net-- 杂七杂八】的代码


    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
  • 相关阅读:
    (兼容IE8)的渐变
    左侧固定,右侧自适应,两列等高并且自适应的第二种办法
    左侧定宽,右侧自适应,两列布局且等高
    下拉框重写
    在页面中输出当前客户端时间
    用哈希表去数组重复项,有详细注释
    求数组最大值、求和、乘法表、取整
    类似新浪微博输入字符计数的效果
    将博客搬至CSDN
    Mysql常用操作
  • 原文地址:https://www.cnblogs.com/easy5weikai/p/3795530.html
Copyright © 2020-2023  润新知