Skip to content

Validate model state not working? #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wayne-o opened this issue Sep 25, 2018 · 5 comments
Closed

Validate model state not working? #411

wayne-o opened this issue Sep 25, 2018 · 5 comments

Comments

@wayne-o
Copy link
Contributor

wayne-o commented Sep 25, 2018

Description

I am trying to use #316 by adding this to my Models:

 [Required(AllowEmptyStrings=false)] 
[StringLength(30, MinimumLength = 5, ErrorMessage = "Invalid - Name needs to be at least 5 characters long")]

And this in my startup:

 services.AddMvcCore()
                .AddDataAnnotations()

But it seems to completely ignore it -is there anything else I need to do to get this to work?

...

Environment

  • JsonApiDotNetCore Version: latest stable (v2.5.2)
  • Other Relevant Package Versions:
@wayne-o
Copy link
Contributor Author

wayne-o commented Sep 25, 2018

I'm trying upgrading to the latest beta - I'll come back with the result

@wayne-o
Copy link
Contributor Author

wayne-o commented Sep 25, 2018

No change :/ even latest does not seem to apply

@jaredcnance
Copy link
Contributor

Have you enabled ValidateModelState ? This was put behind a feature flag since it wasn't initially checked and would have been a breaking change.

/// <summary>
/// Whether or not to validate model state.
/// </summary>
/// <example>
/// <code>
/// options.ValidateModelState = true;
/// </code>
/// </example>
public bool ValidateModelState { get; set; }

@wayne-o
Copy link
Contributor Author

wayne-o commented Sep 25, 2018

Ahhhh ok - trying now :)

@wayne-o
Copy link
Contributor Author

wayne-o commented Sep 25, 2018

Works perfectly :)

@wayne-o wayne-o closed this as completed Sep 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants