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

1.8 KiB

title author description manager ms.author ms.date ms.prod ms.technology ms.topic uid
Controller methods and views rick-anderson Working with controller methods, views and DataAnnotations wpickett riande 03/07/2017 asp.net-core aspnet get-started-article 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 isn't 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-csharp]

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-csharp]

[!INCLUDEadding-model]

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