Here we are going to build a MVC3 project. Visual Studio 2010 only has MVC 2 project template. In order to use MVC3 we need to download it from Web Platform Installer, and install the MVC3 from it.
We are going to use SqlCE as the database for this MVC3 demo application.
What is SqlCE?
SqlCE is a portable database engine which doesn't require installation.
See Scottgu's blog:
http://weblogs.asp.net/scottgu/archive/2011/01/11/vs-2010-sp1-and-sql-ce.aspx
VS2010 SP1(Beta) has the brought the visual studio 2010 some of the new features, such as: IIS express.
After the SP1 installed, we need to install the Sql CE tool for Visual Studio so that visual studio support the Sql CE development.
Now let's create a MVC3 project:
And let's select the internet application. And let's choose the view engine to be Razor.
What is Razor?
We can use the default view engine as aspx(support aspx, ascx, master page et al). About the Razor, Scottgu has an article introducing the new view engine Razor. Basically Razor view engine creates the views with extension of .cshtml. CSHTML uses html and C# code (use @ to determine whether it is a C# code). The advatange of this is has visual studio intellisense support and unittestable.
Right click the App_Data and add new item, we can choose "Sql Server Compact 4 local..." then add a Sql CE database, forexample MyDatabase.sdf.
And then we can use Linq to entity operations to manipulate this database. See Scottgu's blog, Walkthrough1, this is very straightforward, and I am not going to write more in details.
Sql server management studio can also create Sql CE database. use the create new database, I am not going to talk it in details. As create sdf file is not our focus in my this series of articles.
Let's compile and run our web application, see the picture below. We create our first MVC3 application.
No comments:
Post a Comment