You are on page 1of 10

Buu Nguyen

ASP.NET MVC 2.0

.

Session.asax/. Security. Cookie. Routing.master files etc.NET MVC ASP.Technology Stack ASP. Caching.NET Framework (Configuration.ascx/.aspx/. Profiles. . Roles.NET Web Forms ASP.NET Framework . Membership. Application State. .

Controller Factory MvcHandler forwards Controller invokes Model Action produces Action Result View Engine produces View Result defines View .

return Content(rss. return PartialView(). return new HttpUnauthorizedResult().init()."). return PartialView(“partialview”.ppt”. FileResult JsonResult JavaScriptResult HttpUnauthorizedResult EmptyResult return File(“chart. return new EmptyResult(). modelObject). return redirect(“http://www. “application/rss+xml”).microsoft. “application/ppt”). . return View(“view”. modelObject). Return JavaScript("$(‘#table’).com”). return RedirectToRoute(“LogOn”). return Json(someObject).Built-in Action Result Types Action Result Type ViewResult PartialViewResult RedirectToRouteResult RedirectResult ContentResult Examples of Use (in action methods) return View().

Html.BeginForm(…) etc.TextBox(…). Html.g.g. Html.Dynamic Code Options Technique Inline code Description The same old <% … %> and <%= … %> HTML Helpers Partial views Built-in or extension methods for HtmlHelper class. e. which can be reused in many places.g. Html.RenderPartial(“ProductEdit”) Partial action Server controls Invoke an MVC action and render resulted action result. e.RenderAction(“ProductCount") Using standard ASPX control registration & using syntax Note: not recommended unless reusing existing controls (which don’t depend on view state and/or post back) . Render MVC user controls. e.

.BeginForm/For (.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.Common HtmlHelper Methods Method Html.CheckBox/For(…) Html.TextArea/For (…) Html.) <input id=“…" name=“…" type=“…" value=“…" …/> <form id=“…” …>…</form> .RadioButton/For (…) <input checked=“…" id=“…" name=“…" type=“…" value=“…" …/> Html..TextBox/For (…) Html.Hidden/For (…) Html.

including custom attributes .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.

g.Editor(“PropertyName”) Html. Email.EditorForModel() Display Helper Method Html.DisplayForModel() .Label()/LabelFor() to generate the label text Generates a hidden input for the property Indicates the data type of the property (e.Display(“PropertyName”) Html.DisplayFor(model => model.Attribute DisplayName HiddenInput DataType ScaffoldColumn Description Used in Html.PropertyName) Html. NullDisplayText etc.PropertyName) Html.) Indicates that users shouldn’t be able to modify the property Specifies a template to use Editor Helper Method Html. DataFormatString. Password) Indicates whether the property should be shown or ignored DisplayFormat ReadOnly UIHint Adds formatting rules to the property (e.EditorFor(model => model.g.

OnActionExecuted() OnResultExecuting(). OnResultExecuted() OnException() IAuthorizationFilter OnAuthorization() .Types of Filter Filter Type Authorization filter Action filter Result filter Exception filter Interface IActionFilter IResultFilter IExceptionFilter Methods to Override OnActionExecuting().