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) {
         @Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
         @Html.ActionLink("Details", "Details", new { id = item.ID }) |
         @Html.ActionLink("Delete", "Delete", new { id = item.ID })
         @String.Format("{0,g}", item.JoiningDate)

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Back to top button