Adding Validation to Updating a Question
Learn to add validations to update a question.
We'll cover the following...
Steps to add validation to update a question
Let’s add validation to the request for updating a question:
Open
QuestionPutRequest.cs
and add the following using statement:
Press + to interact
using System.ComponentModel.DataAnnotations;
Add the following validation attribute to the
Title
property:
Press + to interact
public class QuestionPutRequest{[StringLength(100)]public string Title { get; set; }public string Content { get; set; }}
We are making sure that a new title doesn’t exceed 100 characters.
Let’s run the app and give this a try by updating a question to have a very long title:
Press + to interact
A validation error is returned as expected.
Stop the app running so that we’re ready to add the next piece of validation. ...