Introducing the ASP.NET MVC 3

Post on 24-May-2015

1.679 views 1 download

Transcript of 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

Who am I?

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

Introducing “MVC Shine” application

• Exercise 2– Implementing simple CRUD functionalities using

Razor view engine

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

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):

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.

Directives

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