5.1: NoteCreate Model
In this section, we'll create the NoteCreate
model that allow us to have some validation for the note properties.
Purpose
Think about the things we'll need to capture when we create a note and save it to the database. We need to create a Title, Content, and DateCreated. Will we provide an id though?
The answer is no. The id will be created after the POST request happens, after we fill out a form with the two properties above. So, we won't provide that. Our .Service and .Data layer will work together to take care of that. Let's talk about that again soon.
NoteCreate model
Right click on ElevenNote.Models
Select Add -> Class and name it
NoteCreate.cs
Make the class public.
Add the following properties (for the
ToString
method, you can typeoverride
and then a space):
Add the
[Required]
annotation to theTitle
property:CTRL .
to bring in the using statementWe can also add annotations to require or limit the number of characters in each field.
Next, we'll make the view for creating a note.
Last updated