--- title: Controller methods and views author: rick-anderson ms.author: riande manager: wpickett ms.date: 10/14/2016 ms.topic: article ms.assetid: c7313211-b271-4adf-bab8-8e72603cc0ce ms.prod: aspnet-core uid: tutorials/first-mvc-app/controller-methods-views --- # Controller methods and views 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. ![image](working-with-sql/_static/m55.png) Open the *Models/Movie.cs* file and add the highlighted lines shown below: [!code-csharp[Main](./start-mvc/sample2/src/MvcMovie/Models/MovieDate.cs?highlight=11,12&range=4-20)] * Right click on a red squiggly line **> Quick Actions**. ![image](controller-methods-views/_static/qa.png) * Tap `using System.ComponentModel.DataAnnotations;` ![image](controller-methods-views/_static/da.png) 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 **> Organize Usings > Remove Unnecessary Usings**. ![image](controller-methods-views/_static/rm.png) The updated code: [!code-csharp[Main](./start-mvc/sample2/src/MvcMovie/Models/MovieDate.cs?highlight=11,12&range=4-20)] We'll cover [DataAnnotations](http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.aspx) in the next tutorial. The [Display](https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayattribute.aspx) attribute specifies what to display for the name of a field (in this case "Release Date" instead of "ReleaseDate"). The [DataType](https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatypeattribute.aspx) attribute specifies the type of the data, in this case it's a date, so the time information stored in the field is not displayed. Browse to the `Movies` controller and hold the mouse pointer over an **Edit** link to see the target URL. ![image](controller-methods-views/_static/edit7.png) The **Edit**, **Details**, and **Delete** links are generated by the MVC Core Anchor Tag Helper in the *Views/Movies/Index.cshtml* file. [!code-HTML[Main](../../tutorials/first-mvc-app/start-mvc/sample2/src/MvcMovie/Views/Movies/IndexOriginal.cshtml?highlight=2,3,4&range=46-50)] [Tag Helpers](../../mvc/views/tag-helpers/intro.md) enable server-side code to participate in creating and rendering HTML elements in Razor files. In the code above, the `AnchorTagHelper` dynamically generates the HTML `href` attribute value from the controller action method and route id. You use **View Source** from your favorite browser or use the **F12** tools to examine the generated markup. The **F12** tools are shown below. ![image](controller-methods-views/_static/f12.png) Recall the format for routing set in the *Startup.cs* file. [!code-csharp[Main](./start-mvc/sample2/src/MvcMovie/Startup.cs?highlight=5&range=79-84)] ASP.NET Core translates `http://localhost:1234/Movies/Edit/4` into a request to the `Edit` action method of the `Movies` controller with the parameter `Id` of 4. (Controller methods are also known as action methods.) [Tag Helpers](../../mvc/views/tag-helpers/index.md) are one of the most popular new features in ASP.NET Core. See [Additional resources](#additional-resources) for more information. Open the `Movies` controller and examine the two `Edit` action methods: ![image](controller-methods-views/_static/1.png) [!code-csharp[Main](start-mvc/sample2/src/MvcMovie/Controllers/MoviesController.cs?range=78-92)] This method will be updated after we add rating (add it to the bind) [!code-csharp[Main](start-mvc/sample2/src/MvcMovie/Controllers/MoviesController.cs?range=101-131)] The `[Bind]` attribute is one way to protect against [over-posting](http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application#overpost). You should only include properties in the `[Bind]` attribute that you want to change. See [Protect your controller from over-posting](http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application#overpost) for more information. [ViewModels](http://rachelappel.com/use-viewmodels-to-manage-data-amp-organize-code-in-asp-net-mvc-applications/) provide an alternative approach to prevent over-posting. Notice the second `Edit` action method is preceded by the `[HttpPost]` attribute. [!code-csharp[Main](start-mvc/sample2/src/MvcMovie/Controllers/MoviesController.cs?range=101-131&highlight=1)] The `HttpPostAttribute` attribute specifies that this `Edit` method can be invoked *only* for `POST` requests. You could apply the `[HttpGet]` attribute to the first edit method, but that's not necessary because `[HttpGet]` is the default. The `ValidateAntiForgeryTokenAttribute` attribute is used to prevent forgery of a request and is paired up with an anti-forgery token generated in the edit view file (*Views/Movies/Edit.cshtml*). The edit view file generates the anti-forgery token with the [Form Tag Helper](../../mvc/views/working-with-forms.md). [!code-HTML[Main](start-mvc/sample2/src/MvcMovie/Views/Movies/Edit.cshtml?range=9)] The [Form Tag Helper](../../mvc/views/working-with-forms.md) generates a hidden anti-forgery token that must match the `[ValidateAntiForgeryToken]` generated anti-forgery token in the `Edit` method of the Movies controller. For more information, see [πŸ”§ Anti-Request Forgery](../../security/anti-request-forgery.md). The `HttpGet Edit` method takes the movie `ID` parameter, looks up the movie using the Entity Framework `SingleOrDefaultAsync` method, and returns the selected movie to the Edit view. If a movie cannot be found, `NotFound` (HTTP 404) is returned. [!code-csharp[Main](start-mvc/sample2/src/MvcMovie/Controllers/MoviesController.cs?range=78-92)] When the scaffolding system created the Edit view, it examined the `Movie` class and created code to render `