If we look at the manual here it states that we should use same old ModelState.IsValid
or TryValidateModel()
yet when I create a project, restore it I don't have access to it.
What am I doing wrong?
Here is the manual: https://docs.asp.net/en/latest/tutorials/first-mvc-app/validation.html
The name 'ModelState' does not exist in the current context
using Api.Models;
using Microsoft.AspNetCore.Mvc;
namespace Api.Controllers
{
[Route("api/authorization")]
public class AuthorizationController
{
[Route("login"), HttpPost]
public IActionResult Authorize(UserViewModel model)
{
if (ModelState) // ModelState does not exist.
{
}
return null;
}
}
}
Your controller needs to inherit from ApiController (or Controller). What you have there isn't really a controller!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With