Thursday, 1 May 2014

Razor View Questions & Answers



What is Razor?
Razor is a markup syntax that lets you embed server-based code (Visual Basic and C#) into web pages.
Server-based code can create dynamic web content on the fly, while a web page is written to the browser. When a web page is called, the server executes the server-based code inside the page before it returns the page to the browser. By running on the server, the code can perform complex tasks, like accessing databases.
Razor is based on ASP.NET, and designed for creating web applications. It has the power of traditional ASP.NET markup, but it is easier to use, and easier to learn.

What are Razor Programming Languages?
Razor supports both C# (C sharp) and VB (Visual Basic).

What is Razor Helpers?
ASP.NET helpers are components that can be accessed by single lines of Razor code.
You can build your own helpers using Razor syntax, or use built-in ASP.NET helpers.
Below is a short description of some useful Razor helpers:
·         Web Grid
·         Web Graphics
·         Google Analytics
·         Facebook Integration
·         Twitter Integration
·         Sending Email
·         Validation


Is, Razor is a case sensitive language or Not?
Yes, Razor is case sensitive language.

What is Variables in Razor?
Variables are named entities used to store data. The name of a variable must begin with an alphabetic character and cannot contain whitespace or reserved characters.

How can you use Razor to serve bundled CSS or JavaScript files?
In a nutshell? Very cleanly in an intuitive way. MVC 4 has a brand new syntax to serve bundled content as shown:
@Scripts.Render("~/Scripts/cart/js")
@Styles.Render("~/Content/cart/css", "~/Content/order/css")

What are the Advantages of  Razor View Engine? 
Compact, Expressive, and Fluid: Razor minimizes the number of characters and keystrokes required in a file, and enables a fast, fluid coding workflow. Unlike most template syntaxes, you do not need to interrupt your coding to explicitly denote server blocks within your HTML. The parser is smart enough to infer this from your code. This enables a really compact and expressive syntax which is clean, fast and fun to type.
Easy to Learn: Razor is easy to learn and enables you to quickly be productive with a minimum of concepts. You use all your existing language and HTML skills.
Is not a new language: We consciously chose not to create a new imperative language with Razor. Instead we wanted to enable developers to use their existing C#/VB (or other) language skills with Razor, and deliver a template markup syntax that enables an awesome HTML construction workflow with your language of choice.
Works with any Text Editor: Razor doesn’t require a specific tool and enables you to be productive in any plain old text editor (notepad works great).
Has great Intellisense: While Razor has been designed to not require a specific tool or code editor, it will have awesome statement completion support within Visual Studio. We’ll be updating Visual Studio 2010 and Visual Web Developer 2010 to have full editor intellisense for it.
Unit Testable: The new view engine implementation will support the ability to unit test views (without requiring a controller or web-server, and can be hosted in any unit test project – no special app-domain required).

In which part of the Asp.net MVC Page life cycle, Razor engine will be used?
Razor kicks in at Execute result in asp.net MVC Page life cycle.

What is the file extension of Razor view engine?
Web pages with Razor syntax have the special file extension cshtml (Razor with C#) or vbhtml (Razor with VB).

What Template does Razor view engine uses?
Instead of MasterPages for the template, Razor uses Layouts.

How to add Namespaces in Razor view engine?
@using YourCustomNamespace
Eg : @using  EmployeeNamespace


How Variables are declared in Razor View Engine?
Variables are declared with the var keywords.

How inline expressions are declared in Razor View Engine?
All the inline expressions like variables and functions start with @.
Eg: <li @Html.Css("selected", Model.Mode == "map" )>STUFF</li>

What are the Different View engines which can be used in asp.net MVC?
Asp.net supports different view engines apart from Razor and Asp.net View Engine.

No comments:

Post a Comment