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 core model validation doesn't work as expected

According to Microsoft documentation, if a model property is not-nullable, it is considered required by default, so there's no need to explicitly add the [Required] attribute. By default, the validation system treats non-nullable parameters or…
Iliyan Ivanov
  • 407
  • 1
  • 4
  • 17
0
votes
1 answer

Why Required attribute in model validation works for some but not for some other?

I have following Controller Post method: [Route("")] [ResponseType(typeof(CardPost))] [HttpPost] public IHttpActionResult PostCard([FromBody] CardPost CardMetaData) { if (!ModelState.IsValid) { BadRequest(ModelState); }//Property is…
S.A. Khalili
  • 43
  • 1
  • 9
0
votes
1 answer

Model validation is Not working for the derived classes. even though i have mentioned the known types

I am using asp.net core 2.2 and model validation for server side validation. Its working fine except for known types. this is my class structure //Main Class [DataContract] [KnownType(typeof(SubClass2))] …
0
votes
1 answer

In ASP.NET MVC, how to get the element (from a list) that generated validation error in a Model-Validation

I have an API Controller with the following Action header: public IHttpActionResult Post(InvoicesDTO invoices) where InvoicesDTO is as follows: public class InvoicesDTO { public int IdHeader { get; set; } …
MorgoZ
  • 2,012
  • 5
  • 27
  • 54
0
votes
1 answer

How to reset the formatted ErrorMessages of the validation attributes in ASP.NET MVC?

I used a Custom validation attribute -AmountShouldBeLessOrEqualAttribute- that its validation process related to value of another property and this attribute works successfully. But in the following scenario I have a problem with it: Start the…
Ramin Bateni
  • 16,499
  • 9
  • 69
  • 98
0
votes
1 answer

How to Show Property value in Error Message

I'm using Model validation to show the error message. like below public class ClientData { [DataMember] [MaxLength(10, ErrorMessage = "ERR-ClientSequenceId-02:Enter maximum of 10 characters")] public string CSeqId { get; set; } …
0
votes
1 answer

Validate Post Data in ASP.NET MVC

I have this controller method below: [HttpPost] public ActionResult Login(UserDetails userdetails) What did I do so far ? Replaced potential SQL Candidates in my form (via JQuery side , eg. replace '&' by 'amp') I have added ModelState.IsValid()…
0
votes
2 answers

Standard way of passing input to WebAPI for number data types?

Can someone tell about passing input for WebApi for number data types i.e int, long etc. public class Emp { public int Id { get; set; } public long Volume { get; set; } } Input set 1: { "Id" : "1", "Volume" : "200" } this is…
Magendran V
  • 1,411
  • 3
  • 19
  • 33
0
votes
0 answers

xamarin forms built in validation from .net core

According to the documentation, the model validations for Apis can be done something like this: public IActionResult Use(Batman batman) { if (ModelState.IsValid) return Ok(); return BadRequest(ModelState); } Or for .net core 2.1, public…
Neville Nazerane
  • 6,622
  • 3
  • 46
  • 79
0
votes
2 answers

ASP NET Core 2 Model Validation Incorrect

I am working on a test ASP.NET Core 2.0 service to expand my programming knowledge to include server side experience. I have a Registration Model class that is sent to the service when a user is registering in my application. My RegistrationModel…
CraftyCoder
  • 55
  • 1
  • 7
0
votes
0 answers

Find the actual Data Type of the properties from JSON object in ASP.NET Core

In my program, I have an ActionFilter class for model validation. The action filter is working fine to validate the model. But the problem is before validating the JSON object, JSON.Net deserialize the JSON object and I need to know the data type of…
mnu-nasir
  • 1,642
  • 5
  • 30
  • 62
0
votes
2 answers

ASP.NET MVC Dynamic Views

I Posted the background to this question a few days ago.. but the answer is yet incomplete, so re-Posting with a summary. I'm developing a MVC 3 Razor Web App, in which details of multiple categories of objects are stored. (Vehicles, Houses,…
Azwaan
  • 47
  • 1
  • 9
0
votes
3 answers

Model validation with Razor Pages

I have a form that is at the bottom of the page. When model validation failes on server side return Page() gets me back to the top of the page and that is very inconvenient because the user has to scroll down to the form to see the validation…
0
votes
0 answers

Rails 5 Model Validation on multiple attributes not working

My model validation isn't working as expected although the DB validation works fine. I need to have a unique constraint on the combination of 3 attributes together. The validation should be that if :tag_owner_area is present, there should be no…
P0lska
  • 461
  • 1
  • 6
  • 17
0
votes
1 answer

OnActionExecuting actionContext binding bool parameter turned string

I have an ActionFilterAttribute where I expect a ViewModel with one of its paramaters as a string. I read it in the "OnActionExecuting(HttpActionContext actionContext)" method. As a test, I am sending this parameter as a boolean value: true…
user441365
  • 3,934
  • 11
  • 43
  • 62