Posts

Showing posts with the label Razor

ASP NET Core Client-side libraries management with VS 2017 Library Manager

Image
ASP NET Core Client-side libraries management with VS 2017 Library Manager Few weeks ago I discussed how we could create a healthchek library which would return json status of our application. Using the json, I wanted to make a quick page to display healthchecks in a nice visual. I wanted to quickly add Bootstrap and momentJS . For frontend libraries, I was used to use Bower as it nicely put every frontend package in /bower_components which can be served as static data. But since Bower was announcing that it was no longer supported and requested to use Yarn or NPM, I started to look around for an easier solution than those as I don’t really care about source code of the frontend libraries, all I want is the latest compiled versions. After few minutes of research, I found out that the team in Microsoft felt the same way as I did and already worked on a tool called Library manager (libman) and is available in VS Preview for the moment. Libman gives the benefit to allow developers t...

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 ...