Questions tagged [modelstatedictionary]

14 questions
4
votes
1 answer

How to return ModelState with Forbidden status web api

We can return ModelState with BadRequest from web api in following way: return BadRequest(ModelState); It provides following output: { "Message": "The request is invalid.", "ModelState": { "property": [ "error" …
ctor
  • 805
  • 1
  • 10
  • 26
2
votes
1 answer

How to fix 'Error(s) in loading state_dict for AWD_LSTM' when using fast-ai

I am using fast-ai library in order to train a sample of the IMDB reviews dataset. My goal is to achieve sentiment analysis and I just wanted to start with a small dataset (this one contains 1000 IMDB reviews). I have trained the model in a VM by…
geoph9
  • 357
  • 3
  • 18
2
votes
1 answer

What determines the key in the ModelStateDictionary for Items of Collection Properties

If this is my view model: public class ViewModel{ public string SimpleProperty{get;set;} public SubViewModel ComplexProperty{ get;set;} public SubViewModel[] ComplexPropertyArray{ get; set; } } public class SubViewModel{ …
2
votes
0 answers

.NET: ModelStateDictionary Adapter?

So, I've been messing around with validation in .NET, trying to find a good solid way of implementing validation in a business layer (such as discussed in this MSDN article). The idea is that I pass a controller's ModelState to the business…
Chris
  • 71
  • 5
1
vote
0 answers

Return Custom ValidationResult and access it from controller ModalState in Asp.Net Core

I have same issue as mentioned in this question long back. Return Custom ValidationResult and access it from controller in Asp.Net Core But it didn't concluded with an answer. Please suggest a way to get CustomValidationResult into ModelState of…
1
vote
1 answer

ModelState.Isvalid not work for default value of boolean field

WEB API ---> public async Task CreatePost(ChildClient c) { if(!ModelState.IsValid) { throw ... } .. } public class Client { [Required] public bool HasBaseValue { get; set; } = true; [Required] …
user3711357
  • 1,425
  • 7
  • 32
  • 54
1
vote
1 answer

MVC 4 ModelState invalid because it is trying to auto-fill values and not accept new ones

I have a comments section. In the view there is only a comments editor box. @using (Html.BeginForm(new { courseID = @ViewBag.courseID, userName = @User.Identity.Name })) { @Html.ValidationSummary(true)
C-Pfef
  • 129
  • 1
  • 4
  • 12
1
vote
0 answers

What is the reason to use the ModelState / ModelStateDictionary instead of a service-layer validation check

In many online examples and tutorials we see if (!ModelState.IsValid) { return View(model); } or something similar. I have written a ModelState filter to actually make that check before each action execution. But the built-in component model…
0
votes
0 answers

Sorting error messages with key value and error (.net core)

My error messages (mvc.net core) are not coming in correct order - So I googled and found a solution to sort the error message. I found this post @Html.ValidationSummary() - how to set order of error messages I have two questions: Following this…
0
votes
2 answers

ModelStateDictionary - Identify errors that should not be returned to caller

I have a simple web API that performs some basic validation using validation attributes. If the request does not meet the validation requirements, I then extract the error messages from the ModelStateDictionary and return these to the caller as a…
devklick
  • 2,000
  • 3
  • 30
  • 47
0
votes
1 answer

How to apply partial ModelState validation for JsonPatch in ASP.NET Core

I was struggling with an issue that if you use data annotations for model validation in ASP.NET Core and you run patchDoc.ApplyTo(newData); and then if (!TryValidateModel(newData)) you got model validation errors for operations not included in the…
0
votes
2 answers

Prevent value to be preserved in ModelState

Good day! ASP.NET MVC makes a good job by storing values of inputs during GET/POST cycle inside ModelState and automagically putting them into inputs in case of validation errors. But on my form I have CAPTCHA field which shouldn't be preserved…
artvolk
  • 9,448
  • 11
  • 56
  • 85
0
votes
0 answers

Where do I add this "ControllerHelpers" class?

In a pretty old .NET tutorial, "Nerd Dinner", it talks about using a Helper Class for Rule Violations. Everything seems straight forward except I'm not sure where to put this class so I can reference it. I am pretty new at MVC. All of this below was…
JustJohn
  • 1,362
  • 2
  • 22
  • 44
0
votes
2 answers

Prevent ModelState.IsValid from validating attached entities?

Is there a way to override ModelState.IsValid? Some of the entities to be validated are just attached entities, so all the fields except the ID are not to be validate as the entity is in state Unchanged. Is there a way to do this? Has anyone faced…