ASP.NET MVC 2.0

acceptableseashoreΑσφάλεια

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

81 εμφανίσεις

ASP.NET MVC 2.0

2009
-
12
-
23

Intro

class MainContoller

{


function Index()


{


...

raw

data

HTML

CSS

JavaScript

http://localhost/Main/Index

CONTROLLER

MODEL

VIEW

Sample

public class
MainController

: Controller

{


public ActionResult
Index
(int id)


{


var model = new MainModel(id);


return
View(“Index”, model)
;


}

}

public class
MainModel

{


public int
Id
;


public string
Title
;


public string
Content
;

}

<html>

<body>


<h1>
<%= Model.Title %>
</h1>


<p>
<%= Model.Content %>
</p>

</body>

</html>

MainController.cs

MainModel.cs

Index.aspx

ASPX vs PHP

public class
MainController

: Controller

{


public ActionResult
Index
(int id)


{


var model = new MainModel(id);


return
View(“Index”, model)
;


}

}

<html>

<body>


<h1>
<%= Model.Title %>
</h1>


<p>
<%= Model.Content %>
</p>


<img src=“<%= Html.FindFile(“image.jpg”)
%>” />


<div>
<%= ViewData[“Foo”] %>
</div>

</body>

</html>

MainController.cs

Index.aspx

class
MainController

implements Controller

{


public function
Index
($id)


{


$model = new MainModel($id);


return $this
-
>
View(“Index”, model)
;


}

}

MainController.php

<html>

<body>


<h1>
<?= $Model
-
>Title ?>
</h1>


<p>
<?= $Model
-
>Content ?>
</p>


<img src=“<?= $Html
-
>FindFile(“image.jpg”)
?>” />


<div>
<?= $ViewData[“Foo”] ?>
</div>

</body>

</html>

Index.php

ASP.NET MVC 1.0


community (ms
-
pl)


MVC frame


url rewriting and routing


basic validation


helpers (html generators)


page caching

ASP.NET MVC 2.0


templated helpers


areas


support for Data Annotations


client validation


AsyncController


strongly
-
typed input helpers


bug fixes, minor features

Sample 1

public class ProductViewModel

{


[Price(MinPrice = 1.99)]


public double Price { get; set; }




[Required]


public string Title { get; set; }

}

Sample 2

[ChildActionOnly]

public ActionResult Menu()

{


var menu = ...


return PartialView(menu);

}


Partial rendering

<%= Html.Action("Menu") %>
-

builds a string and then sends to output

<%= Html.RenderAction("Menu") %>
-

direct outtput

Community developers


extra helpers


T4 templates


localization


programming techniques


blogs, tutorials


partial caching (donut caching)


webshop (cart, order, PayPal)


Oxite

Road map


MVC (pattern)


1979


ASP.NET MVC 1.0


17th mar 2009


ASP.NET MVC 2.0 RC


17th dec 2009


ASP.NET MVC 2.0


?, integrated in VS2010

Links


http://haacked.com


http://www.asp.net/mvc/gallery


http://aspnet.codeplex.com


Wikipedia: MVC