List of Posts
This is the complete list of categories of posts written during Sep 2021. They have been ordered by the publish date, with the most recent first.
- Published: 03-Sep-2021This tutorial discusses the most desired scenario where data entry form and the already existing records are shown on the same page. Each record has an edit link adjacent to it. When this link is clicked, the record appears in the same data-entry form, so that the user can make changes and submit it. See the image below for a quick understanding of the problem being addressed here. This tutorial also explains a general scheme for editing with EF Core.
- Published: 04-Sep-2021TempData can be used to pass data from one razor page to another. Although QueryString and Session variables can be used to achieve the same objective, yet TempData provides a briefer and cleaner way, and most importantly, it is built into the ASP.NET framework. The most attractive feature of TempData is that the data is automatically cleared away after a first read/extract operation - whenever it takes place. The tutorial ends with a walkthrough where TempData is saved in one page and used for showing a message on a second page. The message appears only once.
- Published: 05-Sep-2021This tutorial extends the one-textbox FORM that we have implemented for CRUD operations in the previous tutorial (see link below). Now we add a checkbox to that form and observe how easy is it to make an addition to a project that is already CRUD-ready!
- Published: 06-Sep-2021This tutorial extends the FORM that we have implemented in the previous tutorial (see link below). Now we add a radiobuttonlist to that form and observe how easy is it to make an addition to a project that is already CRUD-ready! The radiobuttonlist is backed by a hard-coded C# enumeration. We also explain how to specify the conversion from an enum to an INT data-type on the database side.
- Published: 07-Sep-2021This tutorial extends the FORM that we have implemented in the previous tutorial (see link below). Now we add a dropdownlist to that form and observe how easy is it to make an addition to a project that is already CRUD-ready! A dropdownlist must be backed by a C# collection of SelectListItem objects. We also explain how to add an empty required [-Select-] item to such a dropdownlist.
- Published: 09-Sep-2021This is the simplest introduction to Razor Pages - why you need them, what they are, and how page events and data could be handled with them. See the linked video for a primer information.
- Published: 11-Sep-2021This is a quick and complete explanation of how to integrate your razor pages to a framework such as bootstrap, and how to add and manage your custom CSS, JS and image files in your application. We explain various files such as the _ViewStart file, the _Layout file, and the special directory wwwroot. The concept is similar to that of master pages in the classic ASP.NET. The article also contains a linked video that you can watch for a clearer understanding of how we have integrated bootstrap to a simplest ASP.NET Core application.
- Published: 12-Sep-2021Tag helpers provide a standard way of generating html tags in razor pages. They are interpreted on server side. They are of the same syntax as html tags, so a web-designer can style and script them as he does any other html tag. Razor pages are not enabled for tag helpers by default. In this tutorial we learn how to enable a razor page for tag helpers, and we also learn a walkthrough on using the most common "anchor tag helper" to navigate from one razor page to another.
- Published: 13-Sep-2021An anchor tag helper can be used to specify the name of the click event handler. For this the attribute "asp-page-handler" is set equal to the name of the function in the backing class. Read through this tutorial to understand the whole idea. A video is also attached for a first-hand explanation. The tutorial concludes with a walkthrough that demonstrates how a click event can be handled on the server side.
- Published: 14-Sep-2021This is an introduction to the most common UI Elements that can be used on a FORM. The article starts with a quick introduction to an html form of only one textbox, and then shows how to translate it to a razor form. Then a checkbox, a radiobuttonlist, and a dropdown are successively added one by one to build a full blown razor form. Data is not posted, a topic reserved for the next tutorials.
- Published: 14-Sep-2021A form submit is triggerred by a submit button inside FORM tags. If the method is POST, which is most often the case, then the recommended handler is OnPostAsync. The method should be asynchronous because FORM data is invariably processed through database INSERT and UPDATE queries, which must be done asynchronously. The submitted data can be extracted through the two-way BindProperty. See the linked video for a better understanding.
- Published: 15-Sep-2021This article starts with a brief primer on server side validations and why they should be done. A simple model of just one property is used to explain the whole process - starting from setting the validation error messages to finally inserting validation tags to render the errors. We explain how "asp-validation-for" attributes can be used to display validation errors, and that too, respectively, for each property and at a location just adjacent to its FORM element(see the screenshot below), and also how the ASP.NET Core engine takes care of almost 99% of your work. We also explain how to, optionally, display a gist of all validation errors using the "asp-validation-summary" attribute.
- Published: 16-Sep-2021SaveChanges can fail if a constraint fails, if a connection error occurs or if any generic error occurs. So it should always be wrapped in a try-catch handler to gracefully handle the DbUpdateException. But how to inform the user about such a failure? One way is to use the built-in server side validation to artificially push the error as a validation failure.
- Published: 17-Sep-2021This is a brief explanation of how to specify single primary key on a model through attributes - but this approach fails when multiple columns are to be set as the primary key. We explain that such a composite primary key has to be set through the DbContext. Finally, we explain how to query a record on the basis of its primary key.
- Published: 22-Sep-2021This is an explanation of how an "Area" based ASP.NET Core project can be configured for role and policy based authorization. Authorization can be applied to the entire "Area" directory. We also explain how to specify the login and access denied pages.
- Published: 22-Sep-2021This article starts with an explanation of "SignIn", and then explains the various steps for a signin process. Finally, we discuss what is a returnUrl, and what is LocalRedirect, and when should it be used.
- Published: 22-Sep-2021This is a snippet on showing "You are logged as ..." on every page that an authenticated and authorized user visits. The code can be inserted in a razor page or in a partial page.
- Published: 23-Sep-2021Following is a brief scheme on signing out a logged-in user. A function for sign-out is written in the same file as for the login code. Then this function is called from the click of some anchor link and "SignOutAsync" called to kill the login cookie. Finally, a redirection is done to the login page.
- Published: 28-Sep-2021This is a quick and clean scheme for uploading files to a server. In the first part we demonstrate how to store them into a database table. And, in the second we have a word of caution about putting them into a database. A better strategy would, instead, be to store them on a disk, possibly on a separate partition, and a method for doing this is also explained in the end.
- Published: 28-Sep-2021A file can be downloaded by returning a FileResult. This article explains how a FileResult is created. Finally, a walkthrough is given that shows a complete upload-download scenario.