zoukankan      html  css  js  c++  java
  • 表现层笔记之页面是如何调用

    很久以前就疑惑这段代码是怎么回事(下面还是拿petshop的product.aspx.cs为例吧):

    publicpartialclass Products : System.Web.UI.Page {

    protectedvoid Page_Load(object sender, EventArgs e) {
    //get page header and title
    Page.Title = WebUtility.GetCategoryName(Request.QueryString["categoryId"]);
    }
    }

    这样这里类Products继承了System.Web.UI.Page这个类,二page类通过继承System.Web.UI.Control类,从而拥有了web控件的特性,它同时继承了IHttpHandler这个接口,作为处理Http Web请求的接口。page就是通过Control类继承了Load。张逸老师将了MVC模型在petshop表现层中,但是我对这个模型不太理解。还是先引用下张老师书最经典的例子:

    protectedvoid wzdCheckOut_FinishButtonClick(object sender, WizardNavigationEventArgs e) {
    if (Profile.ShoppingCart.CartItems.Count >0) {//说明有宠物下单了
    if (Profile.ShoppingCart.Count >0) {//我觉得这个多余吧

    // display ordered items
    //应该是显示清单吧 调用CartList.ascx.cs中的Bind函数
    CartListOrdered.Bind(Profile.ShoppingCart.CartItems);

    // display total and credit card information
    ltlTotalComplete.Text = ltlTotal.Text;
    ltlCreditCardComplete.Text
    = ltlCreditCard.Text;

    // create order
    OrderInfo order =new OrderInfo(int.MinValue, DateTime.Now, User.Identity.Name, GetCreditCardInfo(), billingForm.Address, shippingForm.Address, Profile.ShoppingCart.Total, Profile.ShoppingCart.GetOrderLineItems(), null);

    // 调用BLL.Order
    Order newOrder =new Order();
    newOrder.Insert(order);

    // destroy cart
    Profile.ShoppingCart.Clear();
    Profile.Save();
    }
    }
    else {
    lblMsg.Text
    ="<p><br>Can not process the order. Your cart is empty.</p><p class=SignUpLabel><a class=linkNewUser href=Default.aspx>Continue shopping</a></p>";
    wzdCheckOut.Visible
    =false;
    }
    }

    这个事件是Wizard控件的事件,在执行完所有的Wizard步骤后触发。那么这个MVC是怎么样理解的呢?首先从页面控件得到属性,调用OrderInfo订单实体类。然后,调用BLL.Insert方法吧这个OrderInfo实体,插入到数据库。解释:实体类的即是---View、Order对象(上面这段代码调用了Order对像的Insert方法)即是Model、而这个控件FinishButtonClick事件应该就是Controler吧。这个例子为什么典型呢?因为View即影响了Model 的值,而Model的值又反过来影响了View。具体是这样的:View的属性传递给OrderInfo对象,然后调用Order的Insert数据库。而我们上面也调用Profile.ShoppingCart.CartItems.Count 的数量进行了判断,如果它的值是0,那么会在页面进行提示消息。

  • 相关阅读:
    好好活,做有意义的事
    linux运维、架构之路-linux基础知识
    linux运维、架构之路-linux目录结构
    linux运维、架构之路-linux基础优化
    linux运维、架构之路-SSH远程管理服务
    linux运维、架构之路-实时同步方案
    linux运维、架构之路-nfs网络文件系统
    linux运维、架构之路-全网备份项目方案
    linux运维、架构之路-rsync
    编程题
  • 原文地址:https://www.cnblogs.com/huaizuo/p/2110839.html
Copyright © 2011-2022 走看看