Introducing the ASP.NET MVC 3

8
ASP.NET MVC 3 Training for Heroes WELCOME TO MVC SHINE DAY Lê Dương Công Phúc SESSION 2: ASP.NET MVC 3 OVERVIEW

Transcript of Introducing the ASP.NET MVC 3

Page 1: Introducing the ASP.NET MVC 3

ASP.NET MVC 3 Training for Heroes

WELCOME TO MVC SHINE DAY

Lê Dương Công Phúc

SESSION 2: ASP.NET MVC 3 OVERVIEW

Page 2: Introducing the ASP.NET MVC 3

Who am I?

• Lê Dương Công Phúc• Technical evangelism• Software engineer at Vina Digital Co,. Ltd.

Page 3: Introducing the ASP.NET MVC 3

Introducing “MVC Shine” application

• Exercise 2– Implementing simple CRUD functionalities using

Razor view engine

Page 4: Introducing the ASP.NET MVC 3

Razor Syntax

@if (User.Grok(Razor)) {<div>w00t!</div>

}• New, Simplified View Engine• Write fewer lines of code• More natural mix code and markup• Helpers save you time• Compatible with ASP.NET Web Pages in

WebMatrix

Page 5: Introducing the ASP.NET MVC 3

Web Forms vs. PHP vs. Razor

<ul> <% for (int i = 0; i < 10; i++) { %> <li><% =i %></li> <% } %></ul>

<ul> @for (int i = 0; i < 10; i++) { <li>@i</li> }</ul>

Razor (2 markup transitions):

Web Forms (6 markup transitions):

<ul> <?php for ($i = 0; $i < 10; $i++) { echo("<li>$i</li>"); } ?></ul>

PHP(2 markup transitions

& an echo):

Page 6: Introducing the ASP.NET MVC 3

Razor Syntax

Razor ASPX Description

@exp <%: exp %> Encode and output an expression to the page

@(exp) <%: exp %> Explicit expression

@{ stms; } <% stms; %> Execute code statements

@Html.Raw(exp) <%= exp %> Output an expression to the page

@* cmt *@ <%-- cmt --%> Comment out code block

@if(cond) { stm;} else { stms;}

<% if (cond) { stms; } else { stms; } %>

Execute conditional statements

Other constructs work the same way: @foreach, @for, @while, @switch, @try etc.

Page 7: Introducing the ASP.NET MVC 3

Directives

Page 8: Introducing the ASP.NET MVC 3

Layouts make organizing your pages easier

Don’t repeat yourself!Define one layout and use it across your website

Layout.cshtml

Page 1

Page 2

Page 3