View Engine in MVC

MVC View can contain html and server side code such as C# and VB.Net. Browser can understand only html. Browser can not understand C# or VB.Net code. We can create a View in MVC based on View Engine and we have to write code in View as per selected View Engine.

View Engine processes View and it understand server side code. View Engine processes View and generates output in HTML format which browser can understand and display response to user.
View Engine provides a set of syntax to write C# code in the view.View Engine is also responsible to render the view as html.
ASP.Net MVC supports 2 types of View Engine:
1. ASPX View Engine
2. Razor View Engine

Syntax in ASPX View Engine:


C# code


Syntax in Razor View Engine:


C# code


ASPX is older View Engine, supported in MVC 1,2,3 and 4 while Razor is advanced View Engine supported in MVC 3,4 and 5. From MVC 5 onwards only Razor View Engine is supported. So every view in MVC 5 is based on Razor View Engine.

File extension in ASPX View Engine is .aspx while in Razor it is .cshtml (for C#) or .vbhtml(for VB.Net). Razor syntax is very clear and clean. We can write html inside Razor code block.