Razor View Engine in MVC

ASP.NET MVC includes two different view engines, the newer Razor View Engine and the older Web Forms View Engine.

What is Razor?

The Razor view was introduced with ASP.NET MVC 3 and is the default view engine moving forward.

Razor provides a streamlined syntax for expressing views that minimizes the amount of syntax and extra characters. It effectively gets out of your way and puts as little syntax as possible between you and your view markup.

Razor accomplishes this by understanding the structure of markup so that it can make the transitions between code and markup as smooth as possible.

To understand this concept let us see a small example.

After creating a MVC application, add an INDEX view and select Razor as the view engine.Here @ in the code is used because this @ is use to convert the html or view code into cs code. View Engine has an extension named as .cshtml where we can use both cs and html language.

@foreach (var item in Model) {
   <tr>
      <td>
         @Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
         @Html.ActionLink("Details", "Details", new { id = item.ID }) |
         @Html.ActionLink("Delete", "Delete", new { id = item.ID })
      </td>
 
      <td>
         @item.Name
      </td>
 
      <td>
         @String.Format("{0,g}", item.JoiningDate)
      </td>
   </tr>
}
0 0 vote
Article Rating

Do you want to hire us for your Project Work? Then Contact US.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x