Html helpers

A helper is a reusable snippet of Razor syntax exposed as a method. It allows you to separate repeating fragments of the page. It renders HTML to the browser - the return type for a helper is HelperResult. Custom helpers To create your own helper, create a folder called App_Code in the root of your … Continue reading Html helpers

MVC View common layouts

Common layouts You can define a layout that is common to several views as a .cshtml file. You can also divide your template to contain header, footer etc. Use RenderSection and pass the section name as the first parameter and boolean value indicating if the section is required. Let's create CommonLayout.cshtml file like this: Then … Continue reading MVC View common layouts

Razor rendering engine

Razor Razor syntax was introduced with MVC 3 (Visual Studio 2010). In Razor view you can write a mix of HTML tags and server side code. You can use C# to write server side code inside Razor view. Razor uses @ character for server side code instead of traditional <% %>.  The syntax is simpler - … Continue reading Razor rendering engine