Posts

Showing posts with the label Validation

Convert Bootstrap Template to Blazor (Part 5)

This is part 4 in my 7-part series on how to move a free Bootstrap Template and make a Blazor application out of it.  You can read about the other post here: 1.        Part 1 – Create project and Copy over assets 2.        Part 2 - Navigation 3.        Part 3 – Header and Footer 4.        Part 4 – About and Copyright With building this component there are a couple of new concepts that we get to deal with.  We can break down what we need to do into these steps: Create a contact data model with data annotations  Convert the current form into to a Blazor form component  Add the Submit button handler  Create a service to handle the submit  Data Model  The fields we need are listed above, we just need to determine the validation rules.  Here is what we decided:  Name  Required   Max length of 100  Phone Number ...

Blazor Form Validation

Creating an input forms is needed for just about every application.   Creating a form in Blazor is fairly strength forward using the Blazor components and the ASP.Net Core Data Annotations on your model.   The cool part is that the data annotations on your model is the same both in the client and on the server.   Another benefit of Blazor. For this post we will be modifying the standard Weather forecast sample that ships as one of the pages in the project templates.   We will be changing it cities with their temperatures.   I will be using this project for the next couple of blog post, I will just be adding new features to it. Getting Started To get started building input forms, we will create a model and add our data annotations to it.    We have several simple fields and data annotations that deal with required and max length.   These should be common.       public class CityWeatherInfo   ...