Questions tagged [model-validation]

Model Validation is ASP.NET MVC validation method for your models with property attributes. Model validation works for client and server side validation.

For further information you can check Scott Gu's blog post: http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

There is a expansion called "DATA ANNOTATIONS EXTENSIONS" for other custom validation types such as CreditCard, min-max integer value etc. http://weblogs.asp.net/srkirkland/archive/2011/02/23/introducing-data-annotations-extensions.aspx

325 questions
0
votes
1 answer

Prevent .Net Core Remote Validation on form Submit event

I have put a remote validation in Model Class, And it triggered automatically on Sub event and it makes submit button to click twice! to actually work (submit). in a nut shell on Submit button It calls remote validation method. 2 It calls actual…
0
votes
0 answers

C# .NET Core 3 API Model Validation ignores property

Seem to be getting inconsistent returns in my model validation. The main issue that occurs is that whenever a date is invalid/malformed it will stop on all other validations besides date validations. How is it possible that the first request does…
Paaz
  • 133
  • 7
0
votes
1 answer

C# Sharing ValidationContext across different ValidationAttribute fails

Want to apply validation on input model using series of custom validation attributes as mentioned below. If validation result of first validation attribute ie "ValidatorAttributeOne" is true than no need to process "ValidatorAttributeTwo" validation…
0
votes
0 answers

Including range in DefaultModelBindingMessageProvider.SetAttemptedValueIsInvalidAccessor

I'm trying to override the default message of the SetAttemptedValueIsInvalidAccessor(Func) in the startup.cs The default message, services.AddMvcCore().AddMvcOptions(opt =>…
0
votes
0 answers

Hyperparameter in Decision Tree Regressor

I am building a regressor using decision trees. I am trying to find the best way to get a perfect combination of the four main parameters I want to tune: Cost complexity, Max Depth, Minimum split, Min bucket size I know there are ways to determine…
0
votes
1 answer

How to disable model validation to allow fluent validation checking

I have the following controller: [Route("api/[controller]")] public class ReleaseController : BaseController { [HttpPut] public Task UpdateAsync([FromBody] UpdateReleaseForm form, CancellationToken cancellationToken = default) …
0
votes
0 answers

How would you apply fluent APIs to a DTO without this leading to generating a table with EF6?

Can I apply ModelState to an entity mapped from a DTO passed to the controller, and if not how would you apply fluent APIs to a DTO without generating a table? To add more context to this question... I have added some fluent API validations to my…
0
votes
1 answer

Is there any way to disable the validation of inherited properties?

I have the following entities for example: public class BaseClass { [Required] public virtual string DisplayName { get; set; } } public class FirstChildClass: BaseClass { public int Id { get; set; } } public class SecondChildClas:…
0
votes
1 answer

How can i validate a model without binding it with the action method?

I am updating database values using an action method but I am using ajax call to send updated values into that method so I am not binding model with this method so how can I validate the model for this action method such as I am not binding this…
user11974227
0
votes
1 answer

How to return 400 response using the same format that Asp.Net Core validation uses?

I use model validation in Asp.Net Core and it returns 400 errors like that: { "errors": { "MyProperty": [ "Error 1", "Error 2" ] }, "title": "One or more validation errors occurred.", "status":…
0
votes
0 answers

ValidateModel does not work asp.net core 3.0

I trust you doing good, I am new to .net core API, I am doing a model validation, seems like it does not work, Controller Action : [HttpPost] [ValidateModel] [ProducesResponseType(StatusCodes.Status201Created, Type = typeof(ActionLog))] …
UtpMahesh
  • 410
  • 10
  • 25
0
votes
1 answer

Custom validation attribute is not called in Asp.Net Mvc for Url binding, but works for FromBody binding

I have observed a strange behavior in Mvc and not sure if it's a bug or a feature. I have a customer validation attribute MyAttribute and use it e.g. like this: public async Task GetData([MyAttribute] string myparam) Surprisingly…
Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
0
votes
1 answer

Why does not Aspnet.Core model validation throw an exception on Nullable properties?

The following code in C# will throw an InvalidOperationException because it's not allowed to access Value when it is not set. int? a = null; Console.Writeline(a.Value); I have the following code in AspNet.Core: public class Request { [Range(10,…
Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
0
votes
1 answer

Model Validation is working even without ModelState.IsValid netcore3

I wouldn't say this is a problem but something I'm just curious about. So I've just started using .net for web api's, I'd normally use node or python cause they're faster to build, pretty awesome so far. Anyway in my controller method (post), Adding…
0
votes
1 answer

Readable data in querystring on HTTP Get

We've had a penetration test on a website and they're saying we shouldn't be passing readable data in a querystring (it's an Email Address). The querystring is being created by the application when ModelState.isValid fails and it returns the model…
Sherry8212
  • 67
  • 1
  • 11