5.3: Change NoteCreate Model
In this module we'll override the ToString()
method in our models.
Alter ToString()
override
ToString()
overrideIn this section, we alter the ToString()
override with a fat arrow function, also known as a lambda expression. Lambda expressions allow you to write local functions that can be passed as arguments or returned by function calls. In this case, we use it with the ToString()
method to convert Title
to a string regardless of its data type.
Go back to the
NoteCreate.cs
modelChange the
ToString()
override to match this:[MaxLength(8000)] public string Content { get; set; } public override string ToString() => Title;
Do the same for the
NoteListItem.cs
modelnamespace ElevenNote.Models { public class NoteListItem { public int NoteId { get; set; } public string Title { get; set; } [Display(Name="Created")] public DateTimeOffset CreatedUtc { get; set; } public override string ToString() => Title; } }
Last updated