Getting Started with ASP.NET MVC - Hattan Shobokshi

basiliskcanoeΛογισμικό & κατασκευή λογ/κού

2 Νοε 2013 (πριν από 3 χρόνια και 10 μήνες)

86 εμφανίσεις

*
*
Stuttering is a communication disorder
involving disruptions, or “
disfluencies
,” in a
person’s
speech.


*
Across
all cultures, roughly 1% of people
currently has a stuttering disorder
.


*
http://westutter.org/



ASP.NET Web forms &
mvc

Windows Mobile

C#, VB.NET, VBScript,
Javascript


TSQL


Hattan

Shobokshi

Senior Software Engineer

www.hattanshobokshi.com

hattan@gmail.com


*
*
MVC
3
Specifications


*
Brief Overview of new features


*
Demo Razor and New Features in ASP.NET MVC 3


*
Discuss Classic ASP BUG


*
Additional Links


*
QA








*
A new web development framework that allows you to develop web applications on
the Microsoft stack using an MVC Architecture.


*
Current Version is MVC2. MVC3 Beta is out, but not recommended for production
use.


*
MVC3 is an extension of MVC1 and MVC2


*
MVC1 and 2 .NET Framework 3.5 & 4.0. MVC3 4.0 ONLY


*
Is NOT a replacement for traditional ASP.NET web forms.


*
Web Forms
vs

MVC



*
Convention
over configuration




*
Requirements

*

Visual Studio 2010 or Visual Web Developer Express
2010(free)

*
.NET Framework 4.0

*
ASP.NET Web Pages (contains the assembly that
implements the Razor syntax
.)


*
Compatible with MVC2, easy upgrade


*
Side by side install is supported. MVC 1, 2 and 3





http
://
www.microsoft.com/downloads/en/details.aspx?FamilyI
D=0abac7a3
-
b302
-
4644
-
bd43
-
febf300b2c51&displaylang=en


Before installing uninstall previous version of
mvc

3 (preview
)


Install
ASP.NET Web Pages FIRST, then mvc3






*
N
o
Intellinsense

and colorization on Razor Engine


*
Still in Development


class names may change


*
Classic ASP BUG

*
New Features in ASP.NET MVC3

*
Razor View Engine

*
Tooling
Improvements (Project & View Dialog)

*
Global
Filters

*
JSON Model Binding Support

*
Model Validation Improvements.

*
Request Validation Granularity

*
Enhanced Dependency Injection Support

*
Support for Code that Runs Before Views Run

*
Unobtrusive
JQuery

Ajax/Validation

*
New ASP.NET Web Pages helper methods

*
HTML Helpers Support HTML 5 Style attributes

*
Dynamic View Models

*
New
ActionResult

Types


*
A New view Engine for ASP.NET MVC


*
Clean and Concise Syntax. Fluid Workflow.


*
Is Not a new Language. Use existing C# and VB skills


*
Unit Testable WITHOUT a Web Server or ASP.NET Runtime


*
All Existing HTML Helpers work. Even Third Party helpers


*

Q
uickly
integrate server code into your HTML markup with a minimum of keystrokes
.”


*
Currently NO INTELLISENSE or COLORIZATION (by default). These features are coming
and will be
available soon.


*

Code blocks start with @ symbol. No end symbol required (
ie

%>)


*
Web Forms Engine:

<h3> <%:
Model.Name

%></h3>


*
Razor:

<h3>@
Model.Name
</h3>


*
http://
weblogs.asp.net/scottgu/archive/2010/07/02/introducing
-
razor.aspx


*
http://
www.asp.net/webmatrix/tutorials/2
-
introduction
-
to
-
asp
-
net
-
web
-
programming
-
using
-
the
-
razor
-
syntax















*

*
In addition to the
ViewData

dictionary, you can now use
attach properties “on the fly” to a dynamic view model.


*
Public
ActionResult

Index(){


ViewData
[“Message”]=“Hello World”;


return View();

}


*
Public
ActionResult

Index(){


ViewModel.Message
=“
Hello World”;


return View();

}


*
Internally stores property names as key value pairs in a
ViewData

dictionary.


*
Allow you to apply filters to ALL controllers on an application
without having to decorate every controller


*
New
RegisterGlobalFilters
() method in
Global.asax




*
Default model binder now supports
JSON binding


*
Perfect for working with
Jquery

Posted Data


*
HttpNotFoundResult


*
HttpRedirectResult


-

Now contains permanent
redirect
boolean

property


*
HttpStatusCodeResult

*
Request Validation is a security feature that throws an exception if XML or HTML data is found
in HTTP POST data.

*
Previous versions of ASP.NET MVC allowed you to disable Request Validation on an entire
action.
Webforms

does it on an entire page.

*
MVC3 gives you more control. You can specific request validation on specific parameters of a
model.


public
class
BlogPost
{


public
int

Id { get; set; }


public string
Title{
get; set; }


public string
Body{
get; set; }


public
DateTime

PostDate

{
get;set
;}

}


[
ValidateInput
(true, Exclude
="

Body
")]

public
ActionResult

Create(
BlogPost

post)
{ ... }


*
http
://blogs.msdn.com/b/marcinon/archive/2010/10/06/mvc3
-
granular
-
request
-
validation.aspx

*
Chart

@{


var

key = new Chart(width: 600, height: 400)


.
AddTitle
("Chart Title")


.
AddSeries
(


name: "Employee",


xValue
: new[] {


"Peter", "Andrew", "Julie", "Mary", "Dave" },


yValues
: new[] { "2", "6", "4", "5", "3" })


.Write();

}


*
Crypto

*
WebGrid

*
WebImage

*
WebMail


*
http://
www.asp.net/webmatrix/tutorials/6
-
displaying
-
data
-
in
-
a
-
grid

*
http://
www.asp.net/webmatrix/tutorials/7
-
displaying
-
data
-
in
-
a
-
chart



*
HTML
Helpers Support HTML 5 Style
attributes

Underscores in HTML Attributes automatically converted to
dashes.


Html.TextBox
("Name", "Value", new {
data_required

= "true"})


<input data
-
required="true" id="Name" name="Name"
type="textbox" value="Value" />




*
Razor View Engine only


*
_
viewstart.cshtml

or _
viewstart.vbhtml


*
Default location is Views root folder


*
Individual subfolders can have their own
_
viewstart
. Local version takes
precedence



*
In unobtrusive
javascript

mode, automatically generated
javascript

will not appear in HTML elements


*
Cleaner & Concise


*
Turned off by default (in the framework) to support
backwards compatibility


*
New projects will turn have the property activated for
mvc

3.


http://
bradwilson.typepad.com/blog/2010/10/mvc3
-
unobtrusive
-
ajax.html




*
Easier integration with a service locator

*
Optional

*
Dependency
Injection support for
:

*
Controllers
(registering & injecting controller factories, injecting controllers)

*
Views
(registering & injecting view engines, injecting dependencies into view pages)

*

Action
Filters (locating & injecting filters
)

*

Model
Binders (registering & injecting)

*

Value
Providers (registering & injecting)

*

Validation
Providers (registering & injecting)

*

Model
metadata Providers (registering & injecting)



http
://
bradwilson.typepad.com/blog/2010/10/service
-
location
-
pt5
-
idependencyresolver.html


System.Web.Mvc.IDependencyResolver


public interface
IDependencyResolver

{


object
GetService
(Type
serviceType
);


IEnumerable
<object>
GetServices
(Type
serviceType
);

}




*
Affects Classic ASP and
Php



*
MVC3 causes FORM posts to error out


*
http://forums.asp.net/t/1613021.aspx?M
VC3+Beta+Interfering+with+Classic+ASP+
Form+Posts


*
*
http://www.asp.net/mvc/download
/


*
Supported
Operating Systems:

Windows 7;
Windows Server 2003; Windows Server 2008;
Windows Vista

*
.NET 3.5 SP1. Visual Studio 2008, Visual Studio
2008 SP1 or Visual Web Developer 2008 SP1 are
required to use certain parts of this feature
.


http://www.microsoft.com/express/Web/

*
*
Razor View Engine

*
Tooling Improvements (Project & View Dialog)

*
Global Filters

*
JSON Model Binding Support

*
Model Validation Improvements.

*
Request Validation Granularity

*
Enhanced Dependency Injection Support

*
Support for Code that Runs Before Views Run

*
Unobtrusive
JQuery

Ajax/Validation

*
New ASP.NET Web Pages helper methods

*
HTML Helpers Support HTML 5 Style attributes

*
Dynamic View Models

*
New
ActionResult

Types



*
*
Introducing ASP.NET MVC
3 (Preview 1)

http://
weblogs.asp.net/scottgu/archive/2010/07/27/introducing
-
asp
-
net
-
mvc
-
3
-
preview
-
1.aspx


*
ASP.NET MVC 3 Beta Release Notes

http://www.asp.net/learn/whitepapers/mvc3
-
release
-
notes#0.1__
Toc274034224


*
Classic
ASP Bug Discussion

http://
forums.asp.net/t/1613021.aspx?MVC3+Beta+Interfering+with+Cl
assic+ASP+Form+Posts


*
MVC 3 Source Code

http://
aspnet.codeplex.com/releases/view/54306










*
Introducing the Razor Syntax

http
://
weblogs.asp.net/scottgu/archive/2010/07/02/introducing
-
razor.aspx


*
Razor Syntax Tutorial

http
://
www.asp.net/webmatrix/tutorials/2
-
introduction
-
to
-
asp
-
net
-
web
-
programming
-
using
-
the
-
razor
-
syntax


*
Granular Request Validation in ASP.NET MVC 3

http://
blogs.msdn.com/b/marcinon/archive/2010/10/06/mvc3
-
granular
-
request
-
validation.aspx


*
Unobtrusive Ajax

http
://
bradwilson.typepad.com/blog/2010/10/mvc3
-
unobtrusive
-
ajax.html


*
Dependency Injection

http://bradwilson.typepad.com/blog/2010/10/service
-
location
-
pt5
-
idependencyresolver.html










Thank you!