ASP.NET MVC3 快速入门-第一节 概述

clip_image0021.1 本教程的学内容

在本教程中,你将学会如下内容:

· 如何创建一个ASP.NET MVC的工程。

· 如何创建ASP.NET MVC的控制器(controller)与视图(view)。

· 如何使用Entity Framework code-first 范例来创建一个新的数据库。

· 如何获取和显示数据。

· 如何编辑数据并且进行数据的有效性验证。

1.2 建工程

如果要创建一个ASP.NET MVC3的工程时,首先运行Visual Web Developer 2010 Express(本教程中简称“Visual Web Developer”),并且在起始页(start page)中选择“新建项目”。
Visual Web Developer是一个集成开发环境,你可以使用它来进行各种应用程序的开发。在Visual Web Developer的菜单的下面有一个工具条,可以直接点击工具条中的各个工具按钮来进行各种操作,也可以直接点击菜单中的各个菜单项来进行各种操作,此处我们点击“文件”菜单中的“新建项目”菜单项。

clip_image003

图1-1 Visual Web Developer 2010 Express中的起始页

1.3 建你的第一个用程序

你可以使用Visual Basic 或Visual C#作为开发语言来创建应用程序。在本教程中,选择C#来作为开发语言。点击“新建项目”菜单项后,在打开的“新建项目”对话框中,双击左边的“Visual C#”使其成为展开状态,然后点击“Web”,点击右边的“ASP.NET MVC 3 Web 应用程序”,然后在下方的名称文本框中填入应用程序的名称,在本教程中命名为“MvcMovie”,然后点击确定按钮。

clip_image004

图1-2 在新建项目对话框中选择ASP.NET MVC3应用程序并为应用程序命名

在接下来打开的“新ASP.NET MVC 3 项目”对话框中,点击选中“Internet 应用程序”,在“视图引擎”下拉框中保持默认的“Razor”选项不作修改(Razor视图是ASP.NET MVC3种新增的一种十分重要的视图类型,使用它可以使得Web应用程序的开发变得更加方便快捷,在后文中将对此进行详细介绍)。

clip_image005

图1-3 选择项目模板与视图引擎

点击确定按钮,Visual Web Developer会为你所创建的ASP.NET MVC项目提供一个默认模板,这样的话你就拥有了一个可以立刻运行的应用程序。默认的模板中提供的是一个很简单的显示“欢迎使用 ASP.NET MVC!”文字的应用程序,你可以以此作为你的开发起点。

clip_image006

图1-4 Visual Web Developer提供了一个默认的应用程序模板

点击“调试”菜单中的“启动调试”菜单项(该菜单项的快捷键为F5),Visual Web Developer将启动一个内置的服务器,并且在该服务器中打开当前Web应用程序的主页,如图1-5所示。
clip_image007

图1-5 ASP.NET MVC3的默认应用程序模板的调试画面

请注意该页面在浏览器中的地址为“http://localhost:4423/”。其中“localhost”代表了本机上你刚刚创建的Web应用程序的临时网站地址,4423代表了Visual Web Developer使用的一个随机端口,每次调试的时候,Visual Web Developer都会使用这个端口来作为内置服务器的端口号。在各计算机上,该端口号都是不相同的,因为该端口号是Visual Web Developer随机选择的。
在这个模板应用程序的页面的右上角,提供了两个按钮与一个“登录”链接,点击“登录”链接,页面跳转到登录页面,点击“主页”按钮,页面返回到主页,点击“关于”按钮,页面跳转到“关于”页面。
接下来,让我们开始逐步将这个默认的应用程序修改为我们所要的应用程序,在这个过程中逐步了解ASP.NET MVC 3的有关知识。首先,让我们关闭浏览器并开始代码的修改工作。

posted @ 2011-03-23 15:37 haohello 阅读(371) 评论(0) 编辑
posted @ 2011-03-23 15:35 haohello 阅读(1109) 评论(10) 编辑

本教程主要介绍ASP.NET MVC 3的一些基本知识,以及如何使用Microsoft Visual Web Developer Express来建立一个ASP.NET MVC 3的Web应用程序。在开始之前,请确保你已经安装了如下几个开发工具,这些开发工具可以使用Web Platform Installer来统一进行安装。

· Visual Studio Web Developer Express with SQL Express

· ASP.NET MVC 3

· SQL Management Studio

posted @ 2011-03-23 15:35 haohello 阅读(111) 评论(0) 编辑

Orchard是一个网页CMS系统,可以帮助我们通过已有的模块来构建网站。如果我们想要使用Orchard CMS系统更高效地创建网站应用的话,我们需要先熟悉Orchard的一些基本概念以及一些术语。 这篇将解释Orchard系统所用到的一些概念以及它们的作用。

 

General CMS definitions--- CMS的一般定义

CMS中的‘C'的意思是 “content” 也就是内容的意思, 可以这么去理解,所有通过CMS系统管理的东西都可以称之为内容。更准确的来讲,内容就是网站中的所有信息。 举例来说,一篇博客文章,一个评论,一个产品展示信息,或者是导航菜单,亦或者是公司的标识图片,这些都是可以被分辨的、独立的内容。 如果这会儿你在想,内容是网站里的一切,那么就对啦。 如果你还是认为这个概念很模糊的话,那也没什么不对的, 幸运的是,我们将在下面的章节中会更详细具体地阐述不同的内容概念。

Admin panel, Dashboard or back-end 网站的后台管理界面

网站的后台管理界面是我们可以管理网站以及网站内容的地方。 只有被授予了“可以访问后台管理界面”的用户才能访问和管理网站及网站中的内容。 这就是CMS中’M’ 的意思。

image

 

CMS中的S

'S' 在 CMS的意思是系统,这个概念应该不会听起来那么模糊。CMS是通过一种系统的方式来管理内容的:所有的内容都可以以同样的方式被管理。
举例来说,你可以通过同样的工具来管理博客文章、页面内容以及产品展示信息,这些内容也都可以通过使用常用的模块来添加评论、评分及标签。这样以来,在使用系统时才会有一致的体验,也能使得创建新类型的内容更为简便。

Front-end --前台

前台是网站中所有用户能够访问到的界面。换句话说,前台就是除了后台管理界面之外所有能被公众访问到的部分。

image

 

Setup -- 安装配置

安装配置是将网站从初始状态配置成为可工作状态的一个必须的过程(而且,除此之外,你还有很多要做的,比如说,创建网站的内容)。

image

 

Orchard concepts – Orchard概念

Content Item--内容条目

内容条目是一个单独的一块内容,通常可以用一个单独的网址就可以访问到。例如,页面、博客文章或产品展示。

Content type--内容类型

内容条目是内容类型的实例。换种方式说,内容条目是属于内容类型的类别的。在前一节中,我们讲到了内容条目的例子,页面、博客文章、产品展示,这三个例子也是三个不同的内容类型。

Content Part --内容单元

在Orchard系统里内容类型是由一些小的内容单元组成。 内容单元是内容的最小单位,是可以被其他内容类型重用的。

image

 

 

例如,评论(comments)、标签(tags)或者评分(ratings)都是内容单元,因为它们有着特定的功能,而且可以被任何内容类型所重用。 评论作为内容单元并没有只限定于一个特定的内容类型,比如博客文章。评论在博客文章内容类型中的作用和在其他内容类型中的作用是一样的,没有任何差别。在一个内容类型中只能有一个而且仅有一个同样的内容单元。

Content Field--内容字段

内容字段是可以添加到一个内容类型中的。内容字段有一个名字和一个数据类型,而且是限定于这个内容类型的,就是说,不能像内容单元一样在其他内容类型中重用。 一个 内容类型中可以有很多个有着同样数据类型的内容字段。

例如,一个产品内容类型有一个文本内容字段来代表这个产品的唯一标识,一个数字内容字段表示价格,另一个数字内容字段表示重量。这其中的每个内容字段或许只有对这个产品来说是有意义的,用在其他的内容类型中就不会这样。

注意: 也可以创建一个名为产品的内容单元,这个内容单元包含上面所说的三个内容字段。 这样的话就可以将任何内容类型转化为产品了。 这两种方法在Orchard系统中都是可行的。

Module--模块

Orchard的许多扩展应用都是被创建成模块的。一个模块是Orchard的一组功能扩展,这些扩展被整合在Orchard网站中的Modules目录下的同一个子目录中。
你也可以早Orchard Gallery中找到许多可用的模块。

 

image

 

Feature—功能特性

一个模块可以有一个或多个功能特性,它在逻辑上将这些功能组织了起来,而每个功能却可以单独启用或是禁用。例如,一个自定义的验证模块可以有: OpenID验证功能、Facebook验证功能、LiveID验证功能以及其他的验证功能,这些功能都可以单独地被启用或是禁用。
功能特性可以相互依赖,不管它们是不是在同一个模块中。

image

 

Manifest--清单文件

清单文件是模块或主题中的一个描述这个模块或主题的文本文件。
下面就是清单文件的示例:
Name: Comments
AntiForgery: enabled
Author: The Orchard Team
Website: http://orchardproject.net
Version: 0.9.0
OrchardVersion: 0.9.0
Description: The comments system implemented by this module can be applied to arbitrary Orchard content types, such as blogs and pages. It includes comment validation and spam protection through the Akismet service.
Features:
    Orchard.Comments:
        Name: Comments
        Description: Standard content item comments.
        Dependencies: Settings
        Category: Social

UI composition --界面合成

Orchard中所管理的内容是由不同单元组成的。这就需要一种机制可以统一内容显示,同时也顾及到内容的整体性。这就是为什么我们在讲界面的合成, 很多小块的内容需要和谐地整合在一起以统一的整体来展示。界面合成包含下面所要讲述几个概念。

Theme--主题

在创建一个网站时, 我们都有可能需要能够修改网站的每一处的视觉显示效果。Orchard将内容管理与内容显示很清晰地分离开了。一个主题就是用Orchard所创建的网站的所有界面展示。它包括css样式、图片、布局文件、模板文件甚至是自定义的代码文件。我们也可以创建一个主题继承于来自另一主题的属性,如果你只是想在已有主题基础上做一些小的改动时这将会很有用的。

image

Layout--布局

布局文件是主题中定义页面中的大概组织构成的一个文件。布局文件中定义了一组区块以及这些区块的排列顺序及位置,区块中可以插入内容以及小部件(widgets)。

image

 

Template--模板

每一个内容单元,每个内容字段以及每个小部件都需要在前台有自己的展示以便将它们所表示的数据以用户可以阅读的方式展现出来。 一个模板就是将数据转化为浏览器可以显示的HTML源代码的一个文件。你可以将模板理解为有着预先定义的位置的普通的HTML, 这些预先定义好的位置处就是数据可以插入的地方。
下面就是一个模板的一个简单示例:
<h1>@Model.Title</h1>

Shape --形状

Before displaying something using a template, that something gets transformed into a shape, which is a very malleable object that contains all the information required in order to display it. Before getting rendered by templates, everything gets mapped into a tree of shapes that is a sort of abstract representation of the contents of the final page. The advantage of such trees of shapes is that any module can modify existing shapes or create new ones.
The layout, zones, widgets and content parts all get represented as shapes as part of the rendering process.
One could imagine for example a Gravatar module that would add avatar icon shapes to the comment shapes that were created by the comment module. In the same way, the layers from the widget module are adding widget shapes to the zone shapes of the layout shape.

Placement

When rendering the collections of parts and fields -or any other shapes- that compose a page or content item, Orchard needs to know in what order to do so. Placement.info files are XML files that describe rules that can be used to determine what shapes go into what zones and in what order. This enables not only the rendering of each shape to be customized, but also the order in which they get rendered.
Here is an example of a placement file:
<Placement>
    <Place Parts_Map="Content:10"/>
    <Place Parts_Map_Edit="Content:7.5"/>
</Placement>

Zone

Zones are specific parts of a layout that can be customized by inserting widgets. In some themes, zones are collapsible, which means that they disappear if they contain no active widget.

Widget

A widget is a small fragment of UI that can be added to some or all pages of the site. Examples of widgets are tag clouds, maps, archives, a search form, or recent blog posts.

image

Layer

A layer is a group of widgets (with their specific configuration, which includes their positioning -zone name and ordering-) that is activated by a specific rule.
For example, the TheHomePage layer is activated by a rule that specifically selects the home page. The Default layer is always active no matter what page is displayed. The Authenticated layer is only active when users have identified themselves.
When more than one layer is active on any given page, all the widgets from all those layers get displayed at the same time. Orchard orders them based on their position string.

Security

Users and roles

In Orchard, users can be attributed roles, which can be seen as stereotypes of users. Permissions can then be attributed to roles in order to define who can do what on the site (more on this in the next section). Any user can have one or several roles.
Site owners can create their own roles but Orchard comes with built-in roles that should cover most sites' requirements:
  • Administrator: have full control over the site's settings and contents.
  • Editor: does not create content but edit and publish content created by authors.
  • Moderator: validates user-created contents such as comments.
  • Author: writes and publishes his own content.
  • Contributor: writes content but does not necessarily have the rights to publish it.
  • Anonymous: an unknown user, someone who hasn't logged in.
  • Authenticated: any user who has logged in.

Neither Anonymous nor Authenticated can be assigned to a user manually. Rather, they are determined dynamically at runtime.

Privileges and Permissions

All users don't have the same rights and privileges in Orchard: the site owner can choose who can create content, who can write or validate comments, etc. Rights and privileges are represented as permissions. In Orchard, permissions are granted to roles but are not explicitly denied. In other words if a user belongs to any role that has a given permission, he has that permission. To revoke a permission, you need to either remove a user with the role the permission has been granted to or you need to remove that permission for the whole role.
Some permissions are "effectively granted". This means that they have not been explicitly granted, but that they have been implied by another permission. For example, if you grant the site owner permission, you are implicitly granting all the other permissions.

image

Permissions, as well as their default settings for the built-in roles, are defined by modules. This means that if you build your own module, you can define specific permissions to accompany it.

Site owner

The site owner, sometimes also called "super user" is a special user that is defined at setup time and that has all the rights on the site. It can be changed from the settings admin screen if you have the permission to do so.
There is a permission called "Site Owners Permission" that grants the same right and that is granted by default to only members of the Administrator role. We advise never to grant that permission to any other role.

Development

In this section we will describe concepts that are only required for module developers.

ASP.NET MVC

ASP.NET MVC is the Web framework that Orchard is built on.

Handler

A handler is similar to an MVC filter in that it contains code that will execute for specific events of the request life-cycle. They are typically used to set-up data repositories or to do additional operations when something gets loaded.

Driver

Drivers are similar to MVC controllers, but they act at the level of a content part instead of at the level of the full request. They typically prepare shapes for rendering and handle post-backs from admin editors.

Record

A record is a class that models the database representation of a content part. They are POCOs where each property must be virtual.

Model

What plays the part of the model for a content part is the part class itself. Some parts also define view models, in the form of strongly-typed classes or of more flexible dynamic shapes.

Migration

A migration is a description of the operations to execute when first installing a feature or when upgrading it from a version to the next. This enables smooth upgrades of individual features without data loss. Orchard includes a data migration framework.

Injection

Inversion of Control, or injection, is widely used in Orchard. When any piece of code requires a dependency, it will typically demand the injection of one or several instances of a specific interface. The framework will take care of selecting, instantiating and injecting the right implementations at runtime.
posted @ 2011-03-23 15:18 haohello 阅读(198) 评论(0) 编辑

因为我们中的有些同学对于Orchard以及C#等技术都很陌生,所以我就特别地准备这样一篇文章,以便他们能够更快速的入门。

Orchard是一个基于ASP.NET MVC3的CMS系统,所以要为Orchard单独开发模块的话,得先会ASP.NET MVC3, 所以大概初始的路线应该是这样子的。

 

C#—>HTML/CSS/JavaScript—>ASP.NET--->ASP.NET MVC3--->Orchard

 

posted @ 2011-03-09 15:31 haohello 阅读(291) 评论(0) 编辑

Orchard是一个ASP.NET平台下的免费开源的社区项目,该项目旨在提供基于ASP.NET的应用以及可重用的组件。

利用Orchard我们可以创建基于ASP.NET平台可共享的组件以及扩展应用,可以创建满足最终客户、网页设计人员、开发人员等各种需求的特定网站应用程序。另外,我们也在寻求和现有的类似应用程序的作者们一起合作以便能够更好地帮助他们实现自己的目标。Orchard项目是作为Outercurve基金会旗下的ASP.NET开源平台的一部分发布的。Orchard所使用的许可是基于OSI批准的新BSD许可。

Orchard项目旨在达到以下三个目标:

    * 对最终客户、网页设计人员、开发人员有吸引力的、基于.NET的应用程序
    * 开发出一组可以重用的组件,使得在Orchard平台开发网站应用更为简便
    * 创建一个活跃的社区,以便帮助我们更好的定义这些应用以及扩展程序

近期的计划是,Orchard的目的是发布一个可以使得用户快速创建内容驱动的网站的ASP.NET内容管理系统,这个系统可以使得开发人员通过定制开发单独的模块和主题来提供额外的功能。

posted @ 2011-03-09 15:01 haohello 阅读(339) 评论(0) 编辑
摘要: 打开 Visual C++并创建一个新工程 在文件菜单下选择 New → Project (Ctrl+Shift+N). 选择Win32 Project, 输入工程名字, 然后点击OK. 在工程创建向导里点击 Next, 然后选择Empty Project, 点击 Finish. 给新建的工程中添加一个代码文件: 在工程菜单下选择 Add New Item (Ctrl+Shift+A). 选择 C++ File (.cpp), 输入文件名, 点击 OK. 链接OpenGL 库: 在Project菜单下选择 Project Properties (Alt+F7) . 在左侧的导航面板中 选择 C阅读全文
posted @ 2008-05-11 22:51 haohello 阅读(1844) 评论(1) 编辑


Google Maps API是Google自己推出编程API,可以让全世界对Google Maps有兴趣的程序设计师自行开发基于Google Maps的服务,建立自己的地图网站。以下是我在Google Maps API开发过程中找到的一些API的编程资源,包括中文文档,中文说明,示例等等,希望对Google Maps编程感兴趣的程序员有所帮助。

  中文资料部分 (包括中文的文档说明等,以下的网址都是中文内容。)

  下面的关于API的中文文档

  Google Maps API 第2版中文文档 http://www.step1.cn/GoogleApi/map2/documentation.htm

  Google Maps API 第2版升级指南 http://www.step1.cn/GoogleApi/map2/upgrade.htm

  Google Maps API 第2版类参考 http://www.step1.cn/GoogleApi/map2/reference.htm

  另外一个版本的Google Maps API 2中文文档 http://www.zmap.org/doc/maps/documentation/

  Google Maps API 第1版中文文档 http://www.step1.cn/GoogleAPI/map/documentation.htm

  下面是关于KML文件的中文文档

  Google Earth KML中文说明(一) http://gisman.bokee.com/5294713.html

  Google Earth KML中文说明(二) http://gisman.bokee.com/5294722.html

  Google Earth KML中文说明(基于Google Earth客户端版本3.0 的KML 版本2.0) http://www.step1.cn/googleapi/map/kml.htm

  英文资料部分 (主要是Google官方的文档说明,如果觉得中文翻译的有问题,也可以看看这些原始内容。)

  Google Maps API 官方网 http://www.google.com/apis/maps/

  Google Maps API 英文文档 http://www.google.com/apis/maps/documentation/

  Google Maps API 官方Blog http://googlemapsapi.blogspot.com/

  Google Maps API 论坛 http://groups.google.com/group/Google-Maps-API

  Google KML 的官方文档 http://earth.google.com/kml/

  Google API官方网 http://code.google.com/



posted @ 2008-03-01 00:07 haohello 阅读(125) 评论(1) 编辑


Google Maps API是Google自己推出编程API,可以让全世界对Google Maps有兴趣的程序设计师自行开发基于Google Maps的服务,建立自己的地图网站。以下是我在Google Maps API开发过程中找到的一些API的编程资源,包括中文文档,中文说明,示例等等,希望对Google Maps编程感兴趣的程序员有所帮助。

  中文资料部分 (包括中文的文档说明等,以下的网址都是中文内容。)

  下面的关于API的中文文档

  Google Maps API 第2版中文文档 http://www.step1.cn/GoogleApi/map2/documentation.htm

  Google Maps API 第2版升级指南 http://www.step1.cn/GoogleApi/map2/upgrade.htm

  Google Maps API 第2版类参考 http://www.step1.cn/GoogleApi/map2/reference.htm

  另外一个版本的Google Maps API 2中文文档 http://www.zmap.org/doc/maps/documentation/

  Google Maps API 第1版中文文档 http://www.step1.cn/GoogleAPI/map/documentation.htm

  下面是关于KML文件的中文文档

  Google Earth KML中文说明(一) http://gisman.bokee.com/5294713.html

  Google Earth KML中文说明(二) http://gisman.bokee.com/5294722.html

  Google Earth KML中文说明(基于Google Earth客户端版本3.0 的KML 版本2.0) http://www.step1.cn/googleapi/map/kml.htm

  英文资料部分 (主要是Google官方的文档说明,如果觉得中文翻译的有问题,也可以看看这些原始内容。)

  Google Maps API 官方网 http://www.google.com/apis/maps/

  Google Maps API 英文文档 http://www.google.com/apis/maps/documentation/

  Google Maps API 官方Blog http://googlemapsapi.blogspot.com/

  Google Maps API 论坛 http://groups.google.com/group/Google-Maps-API

  Google KML 的官方文档 http://earth.google.com/kml/

  Google API官方网 http://code.google.com/



posted @ 2008-02-29 23:54 haohello 阅读(57) 评论(0) 编辑
摘要: Google Chart API 参考 中文版文档信息简介Google Chart API 为您提供动态创建图表的功能。单击下边的网址查看示例演示:http://chart.apis.google.com/chart?cht=p3&chd=s:hW&chs=250x100&chl=Hello|World您应该看到如下图表目的本文档为使用 Google Chart API 的...阅读全文
posted @ 2008-02-29 23:52 haohello 阅读(97) 评论(0) 编辑