The error typically means that your
Model
doesn't meet the requirements to be validated. In your example, your
FirstName
,
LastName
,
Email
,
Subject
and
Message
properties are decorated with the
[Required]
attribute. This means that those values shouldn't be
null
and
empty
otherwise your condition
if(ModelState.IsValid)
will be
false
.
To ensure that your model captures the data, I would suggest you to use the debugger, set a break-point at your
ContactForm
Action method and then step into your code. Check the variable
cu
and see if all the properties have values associated on it. Here's one reference that you can use to get started with debugging in Visual Studio:
Learn to debug using the Visual Studio debugger - Visual Studio | Microsoft Docs[
^]