MVC interview questions on razor

1) What is Razor in MVC?
Ans) It’s a light weight view engine. Till MVC we had only one view type, i.e., ASPX. Razor was introduced in MVC 3.

2) Why Razor when we already have ASPX?
Ans) Razor View engine is a part of new rendering framework for ASP.NET web pages. Razor is clean, lightweight, and syntax's are easy as compared to ASPX.
 For example, in ASPX to display simple time, we need to write:

<%=DateTime.Now%>  (Asp.net rendering engine uses opening and closing brackets to denote code (<% %>))

In Razor, it’s just one line of code:

@DateTime.Now 

3) Which is a better fit, Razor or ASPX?
Ans) As per Microsoft, Razor is more preferred because it’s light weight and has simple syntax's.


 

No comments:

Post a Comment