Where() Select()

This post is quick intro for beginners. I’ll introduce you to 2 Linq methods Select and Where. We use those functions to manipulate data set. All 2 can be applied to all types implementing IEnumerable interface. It means that you can apply them to data retrieved from database (IQueryable), list (List/IList implements IEnumerable), arrays (which also implements IEnumerable) and others. It’s important to know that each one of those functions return new IEnumerable. Even if we execute these methods on array (e.g. int[]) it returns enumerable (e.g. IEnumerable<int>). Note that it works a bit different for IQueryable and database operations. Since this is an introductory level post I’ll show you how to use them using array based examples. ...

July 28, 2019 · 2 min · Zbigniew

Razor Pages ajax modals with validation

This tutorial will show you how to create ajax powered Bootstrap modals in Razor Pages. You’ll learn how to dynamically load partial content, how to send/save your form via ajax and how to validate it using Razor Pages as a backend technology. Final proof-of-concept source code is in this GitHub repository. As a side note, if you want to see how to the same thing in ASP.NET Core then go to my other tutorial: ASP.NET Core ajax modals with validation using Bootstrap. ...

June 9, 2019 · 15 min · Zbigniew

C# file status (readable, writeable, is file, is directory)

Every once in a while you have to work with files. This article will teach you how to check wheter or not file is readable or writeable. You’re also going to learn how to check if given file or directory exists. Quick intro to C# File, FileInfo, Directory and DirectoryInfo classes All four classes reside inside System.IO namespace. It’s important to notice the differences between those clasesses, especially in terms of not-Info and Info classes. ...

April 28, 2019 · 3 min · Zbigniew

Handling keyboard shortcuts in JavaScript

Keyboard shortcuts are not only for desktop applications. You can also create shortcuts for web applications, which can come in handly in your MPA or SPA apps. Read on to find out how to create keyboard shortcuts in JavaScript. The key events Inside web browsers we have 3 distinct events related to keyboard events. keyup – fired after you release a key keypress – fired once you press a key, which produces a character value like a letter or number, but not for special characters like CTRL keydown – fired after you press a key We can use these events to call desired function. You can attach events to chosen input fields. Since we want it to work (almost) like a desktop app, we’ll attach the event handler to document. Also, the event handler has one parameter which contains all event properties. ...

March 31, 2019 · 4 min · Zbigniew

Strings in C# - concatenating (joining) and splitting

As a programmer you’ll always have to deal with the strings. In this article you’ll learn the most basic string operations: concatenating/joining and splitting. Concatenating/joining strings Concatenation means that you append a one string at the end of another string. This happens directly or indirectly, but you should know that there are a few ways you can join strings in C#. The + operator The simplest method of joining strings together is the + operator. It’s as easy as putting + in between strings: ...

February 24, 2019 · 5 min · Zbigniew