资料来源:Wild
Country官方网站(www.wildcountry.co.uk)www.wildcountry.co.uk/popup.htm

Our planet is facing an unprecedented mass extinction of species, which
will change life as we know it and ultimately lead to our demise. This
ominous fate for the future makes today’s conservation efforts
indispensable and our only hope for a future of biodiversity and a
healthy earth.

     使用强类型的ViewData好处有许多,比如说在IDE中就会有更好的支持,比如代码提示。同时在View与Controller
之间有更严谨的“约定”。在Suteki.Shop项目中作者对强类型的ViewPage引入是通过MvcContrib实现的,下面就是
其ViewPage<T>代码(Suteki.Shop\Views\ViewPage.cs):     

中文资料提供:台湾攀岩数据库(www.Climbing.org
/ 赵子凯 kevin@climber.idv.tw
情报提供:徐贯中(zhongzhong0505@163.com
中文翻译:蔡沛玲(ema.tsai@msa.hinet.net

As a petition on Care2 explains, one in four mammals are at risk of
extinction today. One would hope that with such daunting facts regarding
extinction, that the government and authorities would step in to help
preserve what is left of our wildlife and natural resources. However,
the petition states that the Maryland Department of Natural Resources is
doing just the opposite – they are promoting and condoning the hunt of
wild American black bears for sport!

public class ViewPage<T> : MvcContrib.FluentHtml.ModelViewPage<T> where T : class 
{
        public ViewPage() : base(new LowercaseFirstCharacterOfNameBehaviour())
        {}
}

July 19 2004: Heliums Sink – Product Recall
In house testing has revealed a potentially serious problem with some
HELIUM KArabINERS. Wild Country are
requesting the immediate return of all HELIUM KARABINERS AND QUICKDRAWS
marked with the folloWING batch
codes:
经测试部分HELIUM钩环潜藏高度危险性. Wild
Country敬告客户立即将有以下批号之HELIUM钩环与快扣送回返修:
AAA, AAB, AAC, AAD, AAE, AAF

In 1953, only twelve black bears remained in Maryland, prompting
conservationists to take action and help rebuild their populations. Over
the decades, bear populations began to grow in the state, and
conservation efforts were not in vain. Since 2004, however, the state
has permitted the hunting of this species, leading to the unnecessary
murderous death of 925 American black bears, 103 of which were cubs.

public class ViewUserControl<T> : MvcContrib.FluentHtml.ModelViewUserControl<T> where T : class
{
        public ViewUserControl() : base(new LowercaseFirstCharacterOfNameBehaviour())
        {}
}

太阳娱乐app_澳门太阳集团城网址,批号位于钩环背

As the petition points out, these black bears are essential for a
healthy ecosystem, planting fruit seeds and controlling larvae and moth
populations. They also form no imminent threat to humans, are not
destructive, and only come into sight of humans as a result of human’s
encroaching on the bears’ natural territory.

    
可以看出ViewPage和ViewUserControl只是对MvcContrib中ModelViewPage,ModelViewUserControl的继承,
代码很简单,没什么太多可说的。

PLEASE RETURN ANY HELIUM KARABINERS IMMEDIATELY TO WILD COUNTRY FOR
INSPECTION.
请立即将HELIUM钩环送回Wild Country做进一步检验。
Alternatively return to us via the shop from which they were purchased.
For help with identifying this product or further information concerning
this recall please contact:
您亦可以选择送回原购买店家。若需该产品识别服务或是对本次撤货更进一步的信息,请洽:
Wild Country, Meverill Road, Tideswell, Nr Buxton, Derbyshire SK17 8PY
Phone: 01298 871010 Fax: 01298 872077
Email: info@wildcountry.co.uk
太阳娱乐app_澳门太阳集团城网址 1

Yet another barbaric bear hunt is scheduled to take place this October
23-26, 2017, and this petition is aimed to speak out against this and
stop it before it is too late.

    
强类型的ViewData使用形如:ViewPage<TViewData>,我们可以通过打开一个View看一下,比如“编辑用户信
息”时的视图头声明部分:
      

Please take a moment to sign this petition in support of Maryland’s
black bears, and please share this with your friends and family to
educate them on this extremely important issue.

<%@ Page Title=”” Language=”C#” 太阳娱乐app_澳门太阳集团城网址 2 Inherits=”Suteki.Shop.ViewPage<ShopViewData>”

Buzz Petition

    
    
   
 其中的ShopViewData就是TViewData。在Suteki.Shop中作者使用ShopViewData对Model中大部分类作了相应
的属性和数据绑定的统一封装,感觉ShopViewData就是Model的集合体或者是“缩影”,这样的好处就我看来主要是在
View中进行强类型ViewData绑定时统一参数,这里感觉有偷懒之嫌。不过因此造成其自身视图数据的“庸肿”,其内部
有太多的属性,还是就是绑定传递时的效率可能也会存在一些问题(只是猜测,未测试过,呵呵)。

Image Source: Wikimedia Commons

     好了,下面就开始正文。
   
     首先我们要看一下Suteki.Common\ViewData文件夹下面的几个类,包括:
    
     IErrorViewData,IMessageViewData,ViewDataBase等,其类图如下:
    太阳娱乐app_澳门太阳集团城网址 3
        
    
     从图中看出,ViewDataBase是其体系“核心”, 其实现了 IMessageViewData,
IErrorViewData这两个接口。
其实体代码如下:   

Want to read more posts like this? Sign up for our newsletter below!​

public abstract class ViewDataBase : IMessageViewData, IErrorViewData
{
        public string Message { get; set; }
        public string ErrorMessage { get; set; }

Enter Your Email Address

        public ViewDataBase WithErrorMessage(string errorMessage)
        {
            this.ErrorMessage = errorMessage;
            return this;
        }

SUBSCRIBE

        public ViewDataBase WithMessage(string message)
        {
            this.Message = message;
            return this;
        }
}

Sponsored Links From The Web

   

This Property Developer Envisions & Creates How We Will Live In The
Future

      该抽象类的属性Message,ErrorMessage分别实现了IMessageViewData和IErrorViewData的接口属性。主要
 用于显示临时操作信息(比如“成功添加用户”,“成功编辑用户”等)。其所提供的两个方法“WithErrorMessage”
 和“WithMessage”只是对相应属性的简单绑定而已。
 
    
有了ViewDataBase之后,下面就来看一下其子类实现了,下面是相应类图:
    太阳娱乐app_澳门太阳集团城网址 4
    
   
正如前面所介绍的那样,子类中最“重要”的当属“ShopViewData”,其包括了基本所有Model中的类型,并将
它们以“属性”的方法提供出来以便于前台View使用,同时ShopViewData还提供了与其属性相关的绑定方法(均以
“With…”开头),下面就是其代码。   

Sansiri Thailand

太阳娱乐app_澳门太阳集团城网址 5太阳娱乐app_澳门太阳集团城网址 6Code
public class ShopViewData : ViewDataBase
{
        public Category Category { get; set; }
        public IEnumerable<Category> Categories { get; set; }

Top 10 Safest Countries For Tourists And Travel

        public Product Product { get; set; }
        public IEnumerable<Product> Products { get; set; }

Bored Articles

        public IEnumerable<Role> Roles { get; set; }

20 Unbelievable Hotels You Won’t Believe Actually Exist!

        public User User { get; set; }
        public IEnumerable<User> Users { get; set; }

www.travelden.co.uk

        public Basket Basket { get; set; }

Top 6 Digital Coins That May Be Worth More Than Bitcoin Some Day

        public Order Order { get; set; }
        public PagedList<Order> Orders { get; set; }
        public OrderSearchCriteria OrderSearchCriteria { get; set; }

WomenArticle.com

        public IEnumerable<Country> Countries { get; set; }
        public Country Country { get; set; }

Wild new world of dating will make ‘swiping right’ seem quaint

        public IEnumerable<CardType> CardTypes { get; set; }

NBC News

        public Postage Postage { get; set; }
        public IEnumerable<Postage> Postages { get; set; }

7 Creative Ways To Save Enough Money To Buy Your First Home

        public PostageResult PostageResult { get; set; }

Bored Articles

        public Card Card { get; set; }

  by Taboola

        public IEnumerable<StockItem> StockItems { get; set; }

Browse through some recent posts below:

        public IEnumerable<Content> Contents { get; set; }

Hampton Creek’s Vegan Scrambled Egg Is Coming to Stores and Restaurants
Soon!

        public IEnumerable<OrderStatus> OrderStatuses { get; set; }

相关文章