diff --git a/aspnetcore/tutorials/first-mvc-app/controller-methods-views.md b/aspnetcore/tutorials/first-mvc-app/controller-methods-views.md index 2641de413811..b174c429c331 100644 --- a/aspnetcore/tutorials/first-mvc-app/controller-methods-views.md +++ b/aspnetcore/tutorials/first-mvc-app/controller-methods-views.md @@ -4,7 +4,7 @@ author: wadepickett description: Part 6, add a model to an ASP.NET Core MVC app monikerRange: '>= aspnetcore-3.1' ms.author: wpickett -ms.date: 03/02/2025 +ms.date: 11/24/2025 uid: tutorials/first-mvc-app/controller-methods-views --- @@ -18,7 +18,7 @@ By [Rick Anderson](https://twitter.com/RickAndMSFT) We have a good start to the movie app, but the presentation isn't ideal, for example, **ReleaseDate** should be two words. -![Index view: Release Date is one word (no space) and every movie release date shows a time of 12 AM](~/tutorials/first-mvc-app/working-with-sql/_static/9/m90.png) +![Index view: Release Date is one word (no space) and every movie release date shows a time of 12 AM](~/tutorials/first-mvc-app/working-with-sql/_static/9/m90-not-formatted.png) Open the `Models/Movie.cs` file and add the highlighted lines shown below: @@ -26,6 +26,10 @@ Open the `Models/Movie.cs` file and add the highlighted lines shown below: `DataAnnotations` are explained in the next tutorial. The [Display](xref:System.ComponentModel.DataAnnotations.DisplayAttribute) attribute specifies what to display for the name of a field (in this case "Release Date" instead of "ReleaseDate"). The [DataType](xref:System.ComponentModel.DataAnnotations.DataTypeAttribute) attribute specifies the type of the data (Date), so the time information stored in the field isn't displayed. +Using the data annotations above, run the application and refresh the `/Movies` page. Because the view markup uses the `@Html.DisplayNameFor` and `@Html.DisplayFor` methods to render the property name and value, the updated `Index` view shows all the fields properly formatted. For example, **Release Date** is now two words and the time information is no longer shown. + +![Index view: Release Date is two words and every movie release date is shown without the time](~/tutorials/first-mvc-app/working-with-sql/_static/9/m90-formatted.png) + The `[Column(TypeName = "decimal(18, 2)")]` data annotation is required so Entity Framework Core can correctly map `Price` to currency in the database. For more information, see [Data Types](/ef/core/modeling/relational/data-types). Browse to the `Movies` controller and hold the mouse pointer over an **Edit** link to see the target URL. diff --git a/aspnetcore/tutorials/first-mvc-app/working-with-sql.md b/aspnetcore/tutorials/first-mvc-app/working-with-sql.md index 5258dabc25c3..33f044248127 100644 --- a/aspnetcore/tutorials/first-mvc-app/working-with-sql.md +++ b/aspnetcore/tutorials/first-mvc-app/working-with-sql.md @@ -120,7 +120,7 @@ Test the app. Stop it and restart it so the `SeedData.Initialize` method runs an The app shows the seeded data. -![MVC Movie app open in Microsoft Edge showing movie data](~/tutorials/first-mvc-app/working-with-sql/_static/9/m90.png) +![MVC Movie app open in Microsoft Edge showing movie data](~/tutorials/first-mvc-app/working-with-sql/_static/9/m90-not-formatted.png) > [!div class="step-by-step"] > [Previous: Adding a model](~/tutorials/first-mvc-app/adding-model.md) diff --git a/aspnetcore/tutorials/first-mvc-app/working-with-sql/_static/9/m90-formatted.png b/aspnetcore/tutorials/first-mvc-app/working-with-sql/_static/9/m90-formatted.png new file mode 100644 index 000000000000..537b30107ae6 Binary files /dev/null and b/aspnetcore/tutorials/first-mvc-app/working-with-sql/_static/9/m90-formatted.png differ diff --git a/aspnetcore/tutorials/first-mvc-app/working-with-sql/_static/9/m90-not-formatted.png b/aspnetcore/tutorials/first-mvc-app/working-with-sql/_static/9/m90-not-formatted.png new file mode 100644 index 000000000000..36bdd1253cd3 Binary files /dev/null and b/aspnetcore/tutorials/first-mvc-app/working-with-sql/_static/9/m90-not-formatted.png differ diff --git a/aspnetcore/tutorials/first-mvc-app/working-with-sql/_static/9/m90.png b/aspnetcore/tutorials/first-mvc-app/working-with-sql/_static/9/m90.png index fecb8f044b3a..d9dd848e8679 100644 Binary files a/aspnetcore/tutorials/first-mvc-app/working-with-sql/_static/9/m90.png and b/aspnetcore/tutorials/first-mvc-app/working-with-sql/_static/9/m90.png differ