AspNetCore.Docs/aspnetcore/tutorials/first-mvc-app/controller-methods-views.md

1.9 KiB

title author description keywords ms.author manager ms.date ms.topic ms.assetid ms.technology ms.prod uid
Controller methods and views rick-anderson Working with controller methods, views and DataAnnotations ASP.NET Core, riande wpickett 03/07/2017 get-started-article c7313211-b271-4adf-bab8-8e72603cc0ce aspnet asp.net-core tutorials/first-mvc-app/controller-methods-views

Controller methods and views

By Rick Anderson

We have a good start to the movie app, but the presentation is not ideal. We don't want to see the time (12:00:00 AM in the image below) and 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

Open the Models/Movie.cs file and add the highlighted lines shown below:

[!code-csharpMain]

Right click on a red squiggly line > Quick Actions and Refactorings.

Contextual menu shows > Quick Actions and Refactorings.

Tap using System.ComponentModel.DataAnnotations;

using System.ComponentModel.DataAnnotations at top of list

Visual studio adds using System.ComponentModel.DataAnnotations;.

Let's remove the using statements that are not needed. They show up by default in a light grey font. Right click anywhere in the Movie.cs file > Remove and Sort Usings.

Remove and Sort Usings

The updated code:

[!code-csharpMain]

[!INCLUDEadding-model]

[!div class="step-by-step"] Previous Next