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

ASP.NET validation of model's nested properties

I'm trying to validate a model containing other objects with validation rules using the TryUpdateModel: public class Post { public User User; } public class User : IValidatableObject { public string Captcha; public…
0
votes
1 answer

compare validation attribute inASP.NET MVC3 not working

I am using Model validation in ASP.NET MVC3. The compare emails validation is not firing at all. I installed DataAnnoatations Extensions for MVC3 also. Below is my code. [Display(ResourceType = typeof(Resources.Views.Account.Local.Create), Name =…
user822848
0
votes
1 answer

Custom Validation Attribute for validation on another field in the Model example Shipped Qty Cannot be > Ordered Qty

I'm working on an ASP.Net core 3.1 MVC project in which I want to create a custom Validator, where shipped qty cannot exceed the ordered qty. I am getting a compile error in the model ([ValidShippedQty(Pending)]) in the ViewModel Error CS0120 An…
0
votes
0 answers

How to validate model attributes without using Data annotation in ASP.NET Core MVC

I want to validate models server-side in ASP.NET Core MVC: public class Transaction { [Key] public int Amount { get; set; } public int Account_Id { get; set; } public string Note { get; set; } public DateTime Date { get; set;…
kalpana
  • 9
  • 1
0
votes
0 answers

Http request body validation

It seems straightforward but I just can't figure out a clean and common way to apply different validation rules to http request body. Binding action parameters to request route or query strings applies the validation data annotations like (required,…
0
votes
0 answers

C# ASP.NET Core 5.0 MVC : validate a list of models created programmatically

Overview I'm working on a project where I ingest a CSV file, where each record results in the creation of a model in the back end. After ingestion, I am able to create a list of models, and I can return the list of models back to the view with no…
0
votes
0 answers

Having trouble with model validation. Is this the next step after selecting a model?

I've run negative binomial hurdle models and chose one based off of AIC and BIC. I'm having trouble figuring out how to validate my model. K-fold test doesn't work because the classifications (more than 2) are not balanced. I can't figure out how to…
myan
  • 1
0
votes
0 answers

FluentValidation: Using IValidatorFactory on a multitenant system

I am running FluentValidation (v 8.6.3) along side FluentValidation.WebApi (v 8.6.1) on.Net 4.7.2 WebAPI stack. Since the system is multitenant, I would like to inject a validation rule per tenant. While from the IoC side that is all wired up…
0
votes
1 answer

How to get parent property name in api model validation process asp.net c#?

I have a class model as below: public class QuataShareSurplussFormModel { public QuataShareSurplussOfferLetterModel offeredLetters { get; set; } [ListValidations] [ListDuplicateValidations] public List
Abolfazl
  • 1,592
  • 11
  • 32
0
votes
0 answers

Issue with IModelValidatorProvider and IModelValidator implementations in ASP.NET Core. Model validation errors are not shown

The task considers two forms: operation registration operation confirmation So 1st form allows to enter the data with respective field validation based on data annotations. Meanwhile 2nd form is designed to show the same data in readonly mode for…
Alex
  • 31
  • 5
0
votes
1 answer

Issue with IModelValidatorProvider and IModelValidator implementations. The generated error is not treated correctly

I try to use IModelValidatorProvider and IModelValidator interfaces in my ASP.NET Core project for respective model validation. Unfortunately it does not work as expected. Namely my ModelValidator class (implements IModelValidator) returns only one…
0
votes
0 answers

Validate nested Json object in custom model binder in .net core

I created a custom model binder in my .NET Core 3.1 API to validate all JSON parameters (by the help of this post How to validate json request body as valid json in asp.net core).Due to security concern I am checking all the incoming request…
user3501613
  • 596
  • 7
  • 28
0
votes
1 answer

In net 5, when binding from body, how to specify that all properties must be present?

Attributes like BindRequired make an action parameter to be required, even the usual model validation attributes can be applied. How can you make all properties from a class be required to be present in the request body?
0
votes
1 answer

How to add a per element validation for en Enumerable in Asp.Net Core?

I have this field that will be mapped from body: [Required] public IReadOnlyCollection Ids { get; set; } I'd like to add a required attribute (or rather any arbitrary validation attribute) to the element itself (i.e. I want every element of…
Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
0
votes
1 answer

laravel is not reading the code(insert validated data) after returning the JSON response to ajax call

$user=new User; $validator=Validator::make($request->all(),$user->rules,$customMessage); if($validator->fails()) { return response()->json(['error'=>$validator->errors()]); } else { return response()->json(['success'=>'Added new…