shzxscmvc/Binders/CartModelBinder.cs

(完整代码) 1KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using shzxscmvc.Models;
using System.Web.Mvc; 

namespace shzxscmvc.Binders
{
    public class CartModelBinder: IModelBinder {
        private const string sessionKey = "cart";
        shzxscentiti ssdb = new shzxscentiti();
        public object BindModel(ControllerContext controllerContext,
                    ModelBindingContext bindingContext)
        {

            // get the Cart from the session
            // 获取会话中的Cart
            shoppingcart cart = (shoppingcart)controllerContext.HttpContext.Session[sessionKey];

            // create the Cart if there wasn't one in the session data
            // 如果会话数据中没有Cart,创建它
            if (cart == null)
            {
                cart = new shoppingcart();
                controllerContext.HttpContext.Session[sessionKey] = cart;
            }

            // return the cart
            // 返回cart
            return cart;
        }

    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。