Slides

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Buu Nguyen

ASP.NET MVC 2.0

Technology Stack

ASP.NET MVC

ASP.NET Web Forms

ASP.NET Framework
(Configuration, Security, Membership, Roles, Profiles, Routing, Caching, Session, Application State, Cookie, .aspx/.ascx/.asax/.master files etc.

.NET Framework

Controller Factory

MvcHandler

forwards

Controller

invokes

Model

Action produces Action Result View Engine produces View Result defines View

Built-in Action Result Types


Action Result Type ViewResult PartialViewResult RedirectToRouteResult RedirectResult ContentResult Examples of Use (in action methods) return View(); return View(view, modelObject); return PartialView(); return PartialView(partialview, modelObject); return RedirectToRoute(LogOn); return redirect(http://www.microsoft.com); return Content(rss, application/rss+xml);

FileResult
JsonResult JavaScriptResult HttpUnauthorizedResult EmptyResult

return File(chart.ppt, application/ppt);


return Json(someObject); Return JavaScript("$(#table).init();"); return new HttpUnauthorizedResult(); return new EmptyResult();

Dynamic Code Options


Technique Inline code Description The same old <% %> and <%= %>

HTML Helpers
Partial views

Built-in or extension methods for HtmlHelper class, e.g. Html.TextBox(), Html.BeginForm() etc.
Render MVC user controls, which can be reused in many places, e.g. Html.RenderPartial(ProductEdit)

Partial action
Server controls

Invoke an MVC action and render resulted action result, e.g. Html.RenderAction(ProductCount")
Using standard ASPX control registration & using syntax
Note: not recommended unless reusing existing controls (which dont depend on view state and/or post back)

Common HtmlHelper Methods


Method
Html.CheckBox/For() Html.TextBox/For () Html.TextArea/For () Html.Password/For ()

Corresponding HTML
<input id=" name=" type="checkbox" value=" /> <input id=" name=" type="text" value=" /> <textarea id=" name=" ></textarea> <input id=" name=" type=" value=" />

Html.RadioButton/For () <input checked=" id=" name=" type=" value=" /> Html.Hidden/For () Html.BeginForm/For (...) <input id=" name=" type=" value=" /> <form id= ></form>

DataAnnotations Validation Attributes

Attribute
Range RegularExpression Required StringLength Validation

Description
Validates whether the property value falls in a min-max range Validates the property against a specified regular expression Validates whether the property value is provided Validates the maximum length of a property value The base class for all validation attributes, including custom attributes

Attribute DisplayName HiddenInput DataType ScaffoldColumn

Description Used in Html.Label()/LabelFor() to generate the label text Generates a hidden input for the property Indicates the data type of the property (e.g. Email, Password) Indicates whether the property should be shown or ignored

DisplayFormat
ReadOnly UIHint

Adds formatting rules to the property (e.g. DataFormatString, NullDisplayText etc.)


Indicates that users shouldnt be able to modify the property Specifies a template to use Editor Helper Method
Html.Editor(PropertyName) Html.EditorFor(model => model.PropertyName) Html.EditorForModel()

Display Helper Method


Html.Display(PropertyName) Html.DisplayFor(model => model.PropertyName) Html.DisplayForModel()

Types of Filter
Filter Type Authorization filter
Action filter Result filter Exception filter

Interface
IActionFilter IResultFilter IExceptionFilter

Methods to Override
OnActionExecuting(), OnActionExecuted() OnResultExecuting(), OnResultExecuted() OnException()

IAuthorizationFilter OnAuthorization()

You might also like