Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



LearnNow


XAMALOT
 


SSWUG

Reader rating:
Click here to read 1 comment about this article.
Article source: CoDe (2011 Mar/Apr)


Article Pages:  1  2 3 4 5 - Next >


The Razor View Engine

The new view engine for ASP.NET MVC and WebMatrix combines simplicity and functionality to facilitate clean view development. In this article, I’ll dive into the Razor View Engine, the new default view engine for the ASP.NET MVC framework and WebMatrix products. Razor’s main goal is to simplify view development and to improve developer productivity while providing a clean view infrastructure.

The ASP.NET MVC product is under constant change and the introduction of a new view engine is not a surprising announcement given the breadth of knowledge that Microsoft has on its side in regards to MVC. Having acquired Hamilton Verissimo (author of the CastleMonorail) and Louis DeJardin (author of the Spark View Engine), the Razor view engine announcement should not surprise you. The Razor view engine blends the gap between the WebForms view engine and the other popular view engines available today.

This article dives into the new default view engine of ASP.NET MVC, Razor. I will start with basic notation and move into more advanced usages with sections, HTML helpers and the layout files. A basic understanding of ASP.NET MVC is recommended as this is not an introduction to ASP.NET MVC or WebMatrix. All examples (except for one) will be given in the context of C#, however, Visual Basic is supported for developing Razor views.

Yet Another View Engine?

During the short life of ASP.NET MVC you’ve been introduced to many view engines - WebForms (default in version 1 and 2 of ASP.NET MVC), Spark, NHaml, NVelocity and many others. The big question you’re probably asking is - why do I need another view engine? The simple answer is - iteration. The ASP.NET MVC team cranks out releases of their products probably faster than any other department in the Developer Division at Microsoft. One very admirable quality that they possess is their great ability to listen to the community when they speak up. For this release, the ASP.NET MVC team listened to the community when they spoke up about the verbosity of syntax that the WebForms view engine required. Mainly users were tired of typing quite verbose statements to accomplish simple things such as outputting variable to the response. A simplified example of such code is as follows:

<%= name %>

The code above outputs the value of the name variable to the response stream. The same code, in Razor is shown below:

@name

Razor not only supplies simplicity in view development but it also saves keystrokes and improves readability inside of the HTML. This is because of the lack of brackets in the Razor language as juxtaposed with the WebForms view engine which required angle brackets to write to the response or enter code notation.

Best of all, you’re given options. You’re not required to choose the Razor view engine (however it is the default in ASP.NET MVC 3) as shown in Figure 1.

Click for a larger version of this image.

Figure 1: When adding a new view, you’re given options to what view engine you’d like to use.

&

By: Donn Felker

Donn Felker is the Principal for Agilevent, a Microsoft Partner he founded in Minneapolis, Minnesota. He is an experienced Software Architect/Developer with over nine years of professional experience in various markets that include: entertainment, health, retail, insurance, financial, and real estate.

He is a Microsoft ASP Insider who currently holds certifications as an MCTS in Web Client Development for the ASP.NET 3.5 Framework, Certified Scrum Master and ITIL Foundation v2. He also holds a bachelors of science in Software Engineering. He writes, presents and consults on various topics ranging from architecture to agile practices to patterns and practices. He is the founder/coordinator of the Twin Cities Give Camp, President of the Twin Cities Developers Guild and the founder of Twin Cities Pragmatic Beer.

You can read Donn’s blog at http://blog.donnfelker.com

dfelker@gmail.com



Article Pages:  1  2 3 4 5 - Next Page: 'Razor Fundamentals' >>

Page 1: The Razor View Engine
Page 2: Razor Fundamentals
Page 3: Working with ViewData, the ViewBag and the Model
Page 4: Organizing Code with Layouts and Sections
Page 5: Using Declarative HTML Helpers

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.6 out of 5

9 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      Sharepoint TechCon

 

SSWUG