Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion aspnetcore/tutorials/first-mvc-app/validation.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
title: Part 9, add validation to an ASP.NET Core MVC app
ai-usage: ai-assisted
author: wadepickett
description: Part 9 of tutorial series on ASP.NET Core MVC.
monikerRange: '>= aspnetcore-3.1'
ms.author: wpickett
ms.date: 01/22/2026
ms.date: 02/27/2026
uid: tutorials/first-mvc-app/validation
---

Expand Down Expand Up @@ -135,6 +136,39 @@ You can use the `DisplayFormat` attribute by itself, but it's generally a good i
* The `DataType` attribute can enable MVC to choose the right field template to render the data (the `DisplayFormat` if used by itself uses the string template).


## Apply migrations

Some validation attributes affect the database schema. For example, `[Required]` makes a column `NOT NULL` and `[StringLength(60)]` limits the column type to `nvarchar(60)`. Run a migration to keep the database schema consistent with the model.

# [Visual Studio](#tab/visual-studio)

From the **Tools** menu, select **NuGet Package Manager > Package Manager Console**.

In the PMC, enter the following commands:

```powershell
Add-Migration New_DataAnnotations
Update-Database
```

# [Visual Studio Code](#tab/visual-studio-code)

[!INCLUDE[](~/includes/RP-mvc-shared/sqlite-warn.md)]

Delete the Migrations folder and the database file, and then run the following .NET CLI commands:

```dotnetcli
dotnet ef migrations add InitialCreate
```

```dotnetcli
dotnet ef database update
```

For more information, see [Resetting all migrations](/ef/core/managing-schemas/migrations/managing?tabs=dotnet-core-cli#resetting-all-migrations).

---

## Additional resources

* [Working with Forms](xref:mvc/views/working-with-forms)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,39 @@ The following code shows combining attributes on one line:

In the next part of the series, we review the app and make some improvements to the automatically generated `Details` and `Delete` methods.

## Apply migrations

Some validation attributes affect the database schema. For example, `[Required]` makes a column `NOT NULL` and `[StringLength(60)]` limits the column type to `nvarchar(60)`. Run a migration to keep the database schema consistent with the model.

# [Visual Studio](#tab/visual-studio)

From the **Tools** menu, select **NuGet Package Manager > Package Manager Console**.

In the PMC, enter the following commands:

```powershell
Add-Migration New_DataAnnotations
Update-Database
```

# [Visual Studio Code](#tab/visual-studio-code)

[!INCLUDE[](~/includes/RP-mvc-shared/sqlite-warn.md)]

Delete the Migrations folder and the database file, and then run the following .NET CLI commands:

```dotnetcli
dotnet ef migrations add InitialCreate
```

```dotnetcli
dotnet ef database update
```

For more information, see [Resetting all migrations](/ef/core/managing-schemas/migrations/managing?tabs=dotnet-core-cli#resetting-all-migrations).

---

## Additional resources

* [Working with Forms](xref:mvc/views/working-with-forms)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,39 @@ The following code shows combining attributes on one line:

In the next part of the series, we review the app and make some improvements to the automatically generated `Details` and `Delete` methods.

## Apply migrations

Some validation attributes affect the database schema. For example, `[Required]` makes a column `NOT NULL` and `[StringLength(60)]` limits the column type to `nvarchar(60)`. Run a migration to keep the database schema consistent with the model.

# [Visual Studio](#tab/visual-studio)

From the **Tools** menu, select **NuGet Package Manager > Package Manager Console**.

In the PMC, enter the following commands:

```powershell
Add-Migration New_DataAnnotations
Update-Database
```

# [Visual Studio Code](#tab/visual-studio-code)

[!INCLUDE[](~/includes/RP-mvc-shared/sqlite-warn.md)]

Delete the Migrations folder and the database file, and then run the following .NET CLI commands:

```dotnetcli
dotnet ef migrations add InitialCreate
```

```dotnetcli
dotnet ef database update
```

For more information, see [Resetting all migrations](/ef/core/managing-schemas/migrations/managing?tabs=dotnet-core-cli#resetting-all-migrations).

---

## Additional resources

* [Working with Forms](xref:mvc/views/working-with-forms)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,39 @@ The following code shows combining attributes on one line:

In the next part of the series, we review the app and make some improvements to the automatically generated `Details` and `Delete` methods.

## Apply migrations

Some validation attributes affect the database schema. For example, `[Required]` makes a column `NOT NULL` and `[StringLength(60)]` limits the column type to `nvarchar(60)`. Run a migration to keep the database schema consistent with the model.

# [Visual Studio](#tab/visual-studio)

From the **Tools** menu, select **NuGet Package Manager > Package Manager Console**.

In the PMC, enter the following commands:

```powershell
Add-Migration New_DataAnnotations
Update-Database
```

# [Visual Studio Code](#tab/visual-studio-code)

[!INCLUDE[](~/includes/RP-mvc-shared/sqlite-warn.md)]

Delete the Migrations folder and the database file, and then run the following .NET CLI commands:

```dotnetcli
dotnet ef migrations add InitialCreate
```

```dotnetcli
dotnet ef database update
```

For more information, see [Resetting all migrations](/ef/core/managing-schemas/migrations/managing?tabs=dotnet-core-cli#resetting-all-migrations).

---

## Additional resources

* [Working with Forms](xref:mvc/views/working-with-forms)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,39 @@ The following code shows combining attributes on one line:

In the next part of the series, we review the app and make some improvements to the automatically generated `Details` and `Delete` methods.

## Apply migrations

Some validation attributes affect the database schema. For example, `[Required]` makes a column `NOT NULL` and `[StringLength(60)]` limits the column type to `nvarchar(60)`. Run a migration to keep the database schema consistent with the model.

# [Visual Studio](#tab/visual-studio)

From the **Tools** menu, select **NuGet Package Manager > Package Manager Console**.

In the PMC, enter the following commands:

```powershell
Add-Migration New_DataAnnotations
Update-Database
```

# [Visual Studio Code](#tab/visual-studio-code)

[!INCLUDE[](~/includes/RP-mvc-shared/sqlite-warn.md)]

Delete the Migrations folder and the database file, and then run the following .NET CLI commands:

```dotnetcli
dotnet ef migrations add InitialCreate
```

```dotnetcli
dotnet ef database update
```

For more information, see [Resetting all migrations](/ef/core/managing-schemas/migrations/managing?tabs=dotnet-core-cli#resetting-all-migrations).

---

## Additional resources

* [Working with Forms](xref:mvc/views/working-with-forms)
Expand Down