Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an ASP.Net MVC View Engine?

There are quite a lot of questions on SO regarding View Engines in ASP.Net MVC, and about using "custom" ones instead of the "default" one. For me as a hobby programmer, the term "View Engine" is new, and I have not been able to understand what it means. So, my questions are:

  1. What is a View Engine?

  2. What does the View Engine do, and which role in the MVC pattern does it play? (Closely related to 1...)

  3. What are the main characteristics/properties of the default View Engine that programmers want to change/avoid by switching to a different View Engine?

  4. What are the main benefits of common other View Engines out there that developers are after when they choose to use a different one than standard? (I've seen the name "Spark View Engine" a bunch of times, and I bet there are others too).

  5. When (in what scenarios) would I want to develop my own View Engine?

There, I think that is all I want to ask (for now). Give me View Engines 101! =)

like image 487
Tomas Aschan Avatar asked May 12 '09 14:05

Tomas Aschan


People also ask

What are ASP.NET MVC view engines?

What is a View Engine in ASP.NET MVC? View Engine is responsible for rendering the view into Html form to the browser. ASP.NET MVC supports web form(. aspx) and Razor View (.

What is view engine used for?

View Engine is responsible for rendering the view into html form to the browser. By default, Asp.net MVC support Web Form(ASPX) and Razor View Engine. There are many third party view engines (like Spark, Nhaml etc.) that are also available for Asp.net MVC.

What is Razor View Engine in ASP.NET MVC?

Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML.

What is view engine in MVC?

View Engine renders the view into html form to the browser. By default, Asp.net MVC comes with two flavors Form (ASPX) and Razor View Engine. There are many types of view engines. These engine works between your view and browser to provide HTML to your browser.

What is the default view engine in aspx?

ASPX View Engine ASPX or Web Form Engine is the default view engine for ASP.NET that is included with ASP.NET MVC from the beginning itself. The syntax used for writing a view with the ASPX View Engine is the same as the syntax used in the ASP.NET web forms.

What is aspx In ASP NET?

ASPX or Web Form Engine is the default view engine for ASP.NET that is included with ASP.NET MVC from the beginning itself. The syntax used for writing a view with the ASPX View Engine is the same as the syntax used in the ASP.NET web forms.

Does ASP NET MVC include a page?

For ASP.NET or Active Server Pages, ASP.NET MVC does not include anything that directly corresponds to a page. In an ASP.NET MVC application, there is not a page on disk that corresponds to the path in the URL that you type into the address bar of your browser. The closest thing to a page in an ASP.NET MVC application is something called a view.


1 Answers

The "view engine" handles the rendering of the view to html, xml or whatever content type it is created to emit. Within "MVC", it would be an aspect of the View (V).

Different view engines have different syntaxes, etc. to manage rendering. The decision to use another view engine is most likely very project/programmer specific. In some cases they may see an actual or perceived limitation of the default view engine; in other cases it may simply be a different design goal or focus.

As far as Spark goes, their focus is to be much more terse than the default view engine and to remain in HTML-like syntax as much as possible instead of dropping into ASP.NET script blocks.

As an end user, the only time you would want to create your own view engine is probably never. ;) It's not a task to be taken lightly, and you'll probably end up re-implementing functionality that already exists in an existing view engine.

Edit

OK. So are the View.aspx files part of the View Engine, or is the View Engine a set of classes that help choose which View.aspx (or other type of response) that should be rendered? How does it work?

The MVC pattern tells you that your model, view and controller will be separate "things". In ASP.NET MVC, the default view engine uses the existing ASP.NET framework, which includes master pages, ASPX files, etc. Spark does something similar, but it's a different engine so it doesn't work exactly the same. So in a general sense the view files are not engine-specific, but the specific files, their layout on disk and their contents are view-engine specific.

like image 86
GalacticCowboy Avatar answered Sep 17 '22 18:09

GalacticCowboy