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.
Open the Models/Movie.cs file and add the highlighted lines shown below:
[!code-csharpMain]
1: #if AddDate
2: #region snippet_1
3: using System;
4: using System.Collections.Generic;
5: using System.Linq;
6: using System.Threading.Tasks;
7:
8: namespace MvcMovie.Models
9: {
10: public class Movie
11: {
12: public int ID { get; set; }
13: public string Title { get; set; }
14:
15: [Display(Name = "Release Date")]
16: [DataType(DataType.Date)]
17: public DateTime ReleaseDate { get; set; }
18: public string Genre { get; set; }
19: public decimal Price { get; set; }
20: }
21: }
22: #endregion
23: #endif
Right click on a red squiggly line > Quick Actions and Refactorings.
Tap using System.ComponentModel.DataAnnotations;
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.
The updated code:
[!code-csharpMain]
1: //#define AddDate
2: #if AddDate
3: #region snippet_1
4: using System;
5: using System.ComponentModel.DataAnnotations;
6:
7: namespace MvcMovie.Models
8: {
9: public class Movie
10: {
11: public int ID { get; set; }
12: public string Title { get; set; }
13:
14: [Display(Name = "Release Date")]
15: [DataType(DataType.Date)]
16: public DateTime ReleaseDate { get; set; }
17: public string Genre { get; set; }
18: public decimal Price { get; set; }
19: }
20: }
21: #endregion
22: #endif
[!INCLUDEadding-model]
Comments (
)
Link to this page:
//www.vb-net.com/AspNet-DocAndSamples-2017/aspnetcore/tutorials/first-mvc-app/controller-methods-views.htm
|