13
ASP.NET MVC CRUSH COURSE 2 ERDEM ERGİN

Asp.net MVC - Course 2

Embed Size (px)

DESCRIPTION

 

Citation preview

ASP.NET MVC CRUSH COURSE 2ERDEM ERGİN

Restful ASP.NET MVC

► Uygulamamızda PUT ve DELETE metotlarını destekleyebilir miyiz?

► HTML formları sadece GET ve POST destekler !!!

<input name="X-HTTP-Method-Override" type="hidden" value="DELETE" />

Asynchronous Actions

► Uzun sürecek bir işlem için IIS thread’ini meşgul etmemek performansı arttırır.

► Kullanıcı açısından değişiklik olmaz !!!

► Controller yerine AsyncController sınıfından türetmek gerek – public void ActionNameAsync(...) – public ActionResult ActionNameCompleted(...)

Default Editor Templates

► Boolean – check-box or 3-state drop-down ► Collection – iterate and show editor (with name style “*n+”)

► Decimal – text box (with formatting) ► HiddenInput – hidden input ► MultilineText – text area ► Object – edit all simple properties ► Password – text box (password) ► String, Text – text box

Default Display Templates

► Boolean – disabled checkbox or 3-state drop-down

► Collection – iterate and display ► Decimal – encoded text (with formatting) ► EmailAddress – auto-linked (with mailto:) ► HiddenInput – encoded text ► Html – unencoded text ► Object – show all simple properties ► String, Text – encoded text ► Url – auto-linked

Custom Templates

Display templates: ► ~/Areas/AreaName/Views/ControllerName/

DisplayTemplates/ ► ~/Areas/AreaName/Views/Shared/DisplayTemplates/ ► ~/Views/ControllerName/DisplayTemplates/ ► ~/Views/Shared/DisplayTemplates/ Editor templates: ► ~/Areas/AreaName/Views/ControllerName/

EditorTemplates/ ► ~/Areas/AreaName/Views/Shared/EditorTemplates/ ► ~/Views/ControllerName/EditorTemplates/ ► ~/Views/Shared/EditorTemplates/

Templates Selection Algorithm

► ModelMetadata.TemplateHint ► ModelMetadata.DataTypeName ► Concrete type name (stripping nullable) ► Simple type? …

– String ► … or interface? …

– Collection (if it implements IEnumerable) – Object

► … or complex type? – Iterate over all base concrete types (stopping before Object)

– Collection (if it implements IEnumerable) – Object

Custom T4 Templates

► WHAT: Generates View and Controller files ► DEFAULT: <vsdir>Common7\IDE\ItemTemplates\CSharp\Web\MVC 2\CodeTemplates

► WHY: Add your own to generate Views and Controllers based on your needs

► Copy CodeTemplates folder in you solution

Server-side Validation Rules

► WHAT: Define how a property is validated in the server side validation

► DEFAULT: Required, Length, wrong type► WHY: Add your own rules

► Write a new ValidationAttribute► Implement the IsValid method► Apply attribute to your model

Client-side Validation Rules

► WHAT: Define how a property is validated in the client-side validation

► DEFAULT: Client-side counterparts of the default server-side validators

► WHY: Add your own validators

Client-side Validation Rules

► First make a server-side validator► Make validation logic in JavaScript► Write adapter to push validation rules to client-side

► Register validation function via JS► Register adapter in Global.asax

HtmlHelpers

► WHAT: Utility functions that hide away the generation of HTML markup or JavaScript code

► DEFAULT: Html.TextBox, Html.Encode, Html.Partial, …

► WHY: “If there is an if, write an Helper”

► Add new methods as extension methods

Teşekkürler

Erdem Ergin@erdemergin