ASP.NET Core ajax modals with validation using Bootstrap

In this tutorial I’m going to show you how to load modals dynamically and how to process forms (within modals) via ajax requests. I’m going to use Bootstrap for modals, because it’s pretty popular, but you may as well use any other UI framework or library for displaying modals. We’ll use jQuery to send ajax and perform modal actions. For the backend, we’ll use .NET Core MVC, but you can replace it with your technology of choice. The keypoint here for you is to find a way to return partial view (that is only HTML of a modal, without the whole layout) and to validate data. ...

May 13, 2018 · 13 min · Zbigniew

The secret "formaction" attribute

Recently I came across a use case of a form which needed two submit buttons. One submit button would just save the data for further edition. Second submit button would save the data and lock it, so you wouldn’t be able to edit it anymore. The best way I know to solve this task is to use formaction attribute. It’s not really a “secret” (as in headline) but it’s lesser known. There is only a one use case for it, but when you need it then there is probably no better way. ...

April 21, 2018 · 2 min · Zbigniew

Value tuples C# 7

Value tuples is one of the features added in C# 7. I’m going to show you why it was introduced to language and how you can use it. Tuple Before we start with value tuples let’s take a look at regular tuples. What’s a Tuple? Basically it’s a set of grouped properties. You can use it to: quickly group related variables pass multiple related values as a single parameter return multiple values from method General characteristics of a Tuple: ...

April 13, 2018 · 3 min · Zbigniew

C# merge dictionary and other tricks

Dictionary is a handy class. It’s a collection of key-value pairs. It is a hash table which means that it has to have unique keys (according to equality comparer). Each key is mapped to a value. Retrieving a value by key is very fast. There are many things you can do with it. In this article I’m going to show you some tricks that may come in handy sometimes. Initializing dictionary In cases when you already have some predefined data you can initialize it using collection initializer. ...

April 6, 2018 · 4 min · Zbigniew

An introduction to unit testing using xUnit.net in .NET Core

Before we get into unit testing we should ask ourselves why would anyone write code to test other code? Is there any reason to do that extra work? It turns out that there are many reasons for that. Firstly, you’re going to make sure that given function works as expected. Secondly, if you decide to change the function, you still have it tested, so in case of some incorrect change you’ll know immediately that something is wrong. Thirdly, your code will have better design, because (once you figure it out) you’ll most likely avoid all dependencies and you’ll make sure that your code is as easy to use as possible. ...

March 30, 2018 · 11 min · Zbigniew