Articles → ASP .NET MVC → View Engines In Asp.Net MVC

View Engines In Asp.Net MVC







  1. ASPX view engine
  2. Razor view engine.

ASPX View Engine




  1. Extension of all your files in view folder is .aspx
  2. Picture showing view files in case of aspx view engine
    Click to Enlarge

  3. < % % > is used for accessing server-side code
  4. <p><% 
                
                
                if (DateTime.Now.Day == 19)
                
                
                
                   {%>
                   
                
                Execute code block 1
                
                
                <%}else {%>
                
                
                Execute code block 2
                
                <%} %>
    </p>



Razor View Engine




  1. Extension of all your files in view folder is .cshtml for C# and .vbhtml for vb.net.
  2. Picture showing view files in case of razor view engine
    Click to Enlarge

  3. @ is used for accessing server-side code.
  4. <p>
            Use this area to provide additional information.
            @if (DateTime.Now.Day == 19)
            {         
    	    <text>  Execute Code block 1</text>            
            }
            else
            {
        
    	    <text>Execute Code block 2</text>
            }
    </p>



What is the difference between razor and webform view engine?


Razor view engineWebform view engine
Razor view engine uses System.Web.Razor namespaceWebform view engine uses System.Web.Mvc. WebformViewEngine namespace
Razor view engine uses @ syntaxWebform view engine uses < % %>
Razor view engine prevents XSS attackWebform view engine does not prevents XSS attack
Razor view engine is slow as compared to webform view engine.Webform view engine is quicker in performance as compared to razor view engine.
Razor view engine supports test driven approachWebform view engine does not support test driven approach



Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, June 9, 2015

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250