码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2014-06-21 00:56:57      阅读:265      评论:0      收藏:0      [点我收藏+]

标签:des   style   class   blog   code   java   

 

Request.Url.PathAndQuery
bubuko.com,布布扣
        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

 

bubuko.com,布布扣
                        <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

 

 

 

【Asp.Net-- 杂七杂八】的代码,布布扣,bubuko.com

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

标签:des   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/easy5weikai/p/3795530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!