1 / 15

Razor

Razor. Remember this?. Web Server. Browser. HTTP Request. Interpret request. Client code (script). Generate HTML and script. HTTP Response (Web page / code). A Revised Model. Web Server (IIS). Browser. HTTP Request. .NET Programming Models (Handlers) Web Forms MVC

adem
Download Presentation

Razor

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Razor

  2. Remember this? Web Server Browser HTTP Request Interpret request Client code (script) Generate HTML and script HTTP Response(Web page / code)

  3. A Revised Model Web Server (IIS) Browser HTTP Request .NET Programming Models (Handlers) Web Forms MVC Web Pages (Razor) Client code (script) HTTP Response(Web page / code)

  4. The .NET Models (Pillars) • Web Forms (These are the traditional ASP.NET applications we have been creating) • Web Pages (Razor) • Looks much like PHP • Model View Controller (MVC) • A framework-based environment

  5. The Razor Model Razor ASP .NET Framework

  6. Razor (Introduction) • It looks much like PHP • Code is embedded into an HTML document • It relies on the .NET framework, as you would expect • It has both C# and VB versions • C# is case sensitive as always • It works with databases • We still have web.config

  7. Razor (Characteristics) • The <% %> syntax is replaced with a leading @ • Code blocks appear in @{} blocks in C# • VB has a similar construct • There are a bunch of new objects

  8. Creating a Razor Project • It’s a project with a template like anything else • Just create a new Web project

  9. Creating a Razor Project

  10. Types of Razor Code Blocks • Inline • The @ character calls a function or evaluates a character within some HTML code • Single Statement • Statement appears in the @{} block as in@{ var x = 10;} • Multi Statement • Use the single statement syntax with multiple statements

  11. Inline (Example) • Code appears embedded inside some HTML • Call the Today method • Note that the .NET classes are the same as always @System.DateTime.Today.ToString()

  12. Single Statement Example • As the name implies, it’s a single statement that appears in a @{}block @{ var x = 10;}

  13. Multi-statement Example • Multiple statements appear in a @{} block • A Semicolon separates each statement @{ Layout = "~/_SiteLayout.cshtml"; Page.Title = "Welcome to my Site!"; }

  14. User Input (Forms) • Unlike Traditional Web forms, we use traditional html input controls • We reference those through the Request object • Example (Get the contents if the input control named text1 • var num1 = Request["text1"]; 

  15. Type Conversion • Like PHP and JavaScript, Razor is loosely typed • Call the “As” functions to convert types • AsInt, AsFloat, Asxxx…

More Related