Sharpen Your MVC Views with Razor By Jon Marozick.

Slides:



Advertisements
Similar presentations
What is XML? a meta language that allows you to create and format your own document markups a method for putting structured data into a text file; these.
Advertisements

Introducing JavaScript
Building Localized Applications with Microsoft.NET Framework and Visual Studio.NET Achim Ruopp International Program Manager Microsoft Corp.
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
Razor. Slide 2 Remember this? Browser Web Server HTTP Request HTTP Response (Web page / code) Client code (script) Interpret request Generate HTML and.
HTML tags Skills: adding HTML tags, text editor IT concepts: plain text, computer components – storage versus memory, separation of content and format.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
Computers: Tools for an Information Age
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Introduction to PHP (Part-1) Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
Developing a Basic Web Page Posting Files on UMBC
Course Textbook: Build Your Own ASP.Net Website: Chapter 2
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
Ori Calvo, 2010 Hi-Tech College
Ori Calvo, 2010 “If people want to have maximum reach across *all* devices then HTML will provide the broadest reach” Scott Guthrie,
Web Pages. WebMatrix Microsoft WebMatrix is a free tool (stack) from Microsoft that developers can use to create, customize, and publish websites to the.
Different ways to implement CSS. There are four different ways to use CSS in your web pages: – Inline CSS – Embedded CSS/Internal CSS – Linked CSS/External.
CIS 375—Web App Dev II ASP.NET 2 Introducing Web Forms.
Learning WebMatrix: Part 2 of 3 Akber Alwani ]
ASP.NET 5 Visual Studio 2015 Templates Bill Wolff Rob Keiser June 10, 2015.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
ULI101 – XHTML Basics (Part II) What is Markup Language? XHTML vs. HTML General XHTML Rules Block Level XHTML Tags XHTML Validation.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
ASP.NET and Model View Control Jesper Tørresø ITNET2 F08.
Learning Web Design: Chapter 4. HTML  Hypertext Markup Language (HTML)  Uses tags to tell the browser the start and end of a certain kind of formatting.
Introduction to Java Server Pages (JSPs) Robert Thornton.
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
HTML Hyper Text Markup Language A simple introduction.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
XP Tutorial 9 1 Working with XHTML. XP SGML 2 Standard Generalized Markup Language (SGML) A standard for specifying markup languages. Large, complex standard.
Getting the most out of ArcGIS Web Application Templates
Jean-Claude Trachsel Senior Consultant Trivadis AG Building a Website with ASP.NET MVC.
Introducing ASP.NET 2.0. Internet Technologies WWW Architecture Web Server Client Server Request Response Network HTTP TCP/IP PC/Mac/Unix + Browser (IE,
George Gonsalves.  Free and lightweight web development tool.  Create, publish, and maintain your website  Optimized for Open Source  Designed for.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Introduction to JavaScript CS101 Introduction to Computing.
ASP.NET MVC Architecture Layouts, Filters, Sections, Helpers, Partial Views, Areas… SoftUni Team Technical Trainers Software University
Web Technologies Lecture 4 XML and XHTML. XML Extensible Markup Language Set of rules for encoding a document in a format readable – By humans, and –
Microsoft ® Official Course Developing a Publishing Site for Web Content Microsoft SharePoint 2013 SharePoint Practice.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
HTML A brief introduction HTML1. HTML, what is? HTML is a markup language for describing web documents (web pages). HTML stands for Hyper Text Markup.
Session 2: Basic HTML HTML Coding Spring 2009 The LIS Web Team Presents.
Creating PHP Pages Chapter 5 PHP Structure and Syntax.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Lesson 2 – Unit B. Quick review 1. What is the name of the eGCC host that you ftp your files? 2. What type of software do you use to create and edit web.
Introduction  “M” “V” “C” stands for “MODEL” “VIEW” “CONTROLLER”. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner.
The idea of adding markup instructions to documents is not new. Before computers, authors would make annotations by hand in their written or typed documents.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Leveraging Web Content Management in SharePoint 2013 Christina Wheeler.
The New Face of ASP.NET ASP.NET MVC, Razor, and jQuery Ido Flatow | Senior Architect | Sela | This session is.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
HTML5 and CSS3 Illustrated Unit B: Getting Started with HTML.
//liveVirtualacademy2011/ What’s New for ASP.NET 4.5 and Web Development in Visual Studio 11 Developer Preview Γιώργος Καπνιάς MVP, MCT, MCDP, MCDBA, MCTS,
Getting Started with HTML
The eclipse IDE IDE = “Integrated Development Environment”
Objective % Select and utilize tools to design and develop websites.
Social Media And Global Computing Introduction to The MVC Pattern
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
ASP.NET Razor Engine SoftUni Team ASP.NET MVC Introduction
ASP MVP Web applications and Razor
Objective % Select and utilize tools to design and develop websites.
Tutorial Developing a Basic Web Page
Presentation transcript:

Sharpen Your MVC Views with Razor By Jon Marozick

What is Razor? New view-engine that is optimized around HTML generation using a code-focused templating approach View-engines are pluggable modules that implement different template syntax options Examples include WebForms, Spark and NHaml

Why Razor? – Consult “Gu” Compact, Expressive, and Fluid Easy to Learn Is not a new language Works with any Text Editor Has great Intellisense Unit Testable

Razor Syntax Code nugets Saves characters and % is hard to reach Don’t have to close code blocks The Razor parser has semantic knowledge of C#/VB code used within HTML-encodes output

@model Directive Easier way to specify strongly-typed models Don’t need inherits anymore By default, Razor will derive the view from the System.Web.Mvc.WebViewPage base class web.config file of your \Views directory specifies base class and imported namespaces

If-Blocks and Multi-line Statements If-blocks require curly braces … } for multi-line statements … ) for multi-token statements

Server-Side Coments … Same as in WebForms Not same as which is an HTML client- side comment

Content and Code Razor is smart enough to know the difference between addresses and code To output where inference may be difficult escape it with Use to denote nested content with no wrapping HTML tags

Layout/Master Pages Layout is the new master as the main content placeholder for additional content placeholders { } blocks are used to define content for each section

DRY Layouts up with _ViewStart The _ViewStart.cshtml file runs before every view is rendered Common view code can be placed here Great place to select view based on detected device (e.g. mobile or tablet)

Sections Use IsSectionDefined() to include default markup with optional sections IsSectionDefined() and RenderSection() cause view to be not directly renderable Sections are not visible more than one level away but can be redefined

Helpers Could use imperative code and add an extension method to HtmlHelper Razor offers declarative helpers either embedded in a page or packaged separately in a class placed in the App_Code folder

Passing Inline Templates as Parameters

Compiled Views true Shifts compiling to build-time rather than run-time Advantage: Catches syntax errors early Disadvantage: Adds to build time If build time is an issue, only turn on in Release mode

Compiled View & Publish Issue See this post and it references this postthis Using the Publish or MsDeploy feature puts files in the obj folder. When build task for compiled views runs the compiler gets confused when it sees the web.config file since there can be only one

Pre-compiling Views RazorGenerator allows pre-compiled views Why pre-compile? Avoids any run-time hit Reduces deployment file set, don’t need cshtml files Unit testing

Scott Gu’s Blog Introducing Razor keyword Layouts with Razor Server-Side Comments and syntax Implicit and Explicit code nuggets Layouts and syntax

References/Resources Converting from Webforms view engine to Razor– Some Tips Converting from Webforms view engine to Razor– Some Tips WebForms to Razor view converter tool Precompile your MVC Razor views Unit test your MVC views C# Razor Syntax Quick Reference Compiling MVC Views In A Build Environment Templated Razor Delegates