Posts

Showing posts with the label Layout

Razor syntax and helpers

Razor syntax and helpers Razor is a HTML templating engine which allows us to construct HTML pages from a combination of data and HTML markup. The power of Razor resides in its typesafety and support for well known operators, conditional if else and iterators for while foreach . It allows us to directly use our C# models in the templates and call functions accessible by the view. Together with intellisense, it is quick way to build UI. Today we will explore some of the features from Razor: 1. Syntax 2. Layout and partial views 3. View components 4. Tag helpers 1. Syntax Razor expressions can written in two ways, implicit or explicit notation. For implicit notation, we start with @ and then we directly have access to values either from the view itself or some we created in the view or static functions. @{ var a = 10; } <label>@a</label> One useful property of the view is the Model . It gives access to the model linked to the page. By going @Model.XXX ...