The ModelState ( System.Web.MVC.ModelState ) is a component in the ASP.Net MVC Framework that manages the state of the Model through Views and Controller classes.
Questions tagged [modelstate]
497 questions
4
votes
1 answer
How to save model state while redirecting to another action in ASP .NET MVC?
I have a Home Controller
public class HomeController : Controller
{
public ActionResult Index()
{
var m = new ModelClass
{
Prop1 = 1,
Prop2 = "property 2"
…

Dmytro
- 16,668
- 27
- 80
- 130
4
votes
1 answer
Limitation of ModelState.IsValid in ASP.NET MVC 3
I always use ModelState.IsValid for check all of my model validation validated correctly in Server Side, but I think there is a limitation to use this. For example I define a Remote Validation attribute, but if I disable javascript then…

Saeid
- 13,224
- 32
- 107
- 173
3
votes
1 answer
DateTime required in ModelState, however never set to be
I have a DateTime field in my form. For whatever reason, everytime I submit the form ModelState comes back as invalid and a message that my date time field (called PostDate) is required, even though in the view model I don't have the required…

Chris
- 7,996
- 11
- 66
- 98
3
votes
4 answers
ASP.NET MVC Posted Model lost interface Property values and ModelState has errors. Model Binding restriction? Serialization issue?
With the following simple action...
[HttpPost]
public PartialViewResult DoSomething(AnimalInfo animalInfo)
{
// animalInfo.AnimalKey SHOULD == DogKey { Id = 1, Name = "Dog" }
// BUT animalInfo.AnimalKey == null
return…

Arkiliknam
- 1,805
- 1
- 19
- 35
3
votes
1 answer
How to organize a Backbone model used by multiple views?
So here is the skinny...(I always talk like a 30s gangster)
I have two Models - ya seee: Company + Date
Setup
The Company model is attached to a drop down list view. It fetches the list of companies from the server. Date is set to today and is…

imrane
- 1,542
- 2
- 16
- 29
3
votes
1 answer
how to use DataAnnotations in desktop application
When we are using EF (f.e.) via MVC, we can use ModelState.IsValid to detect a model can pass DataAnnotations metadata or not. But how can I use DataAnnotations metadata in a desktop (win-forms / wpf) application?
More:
In fact, I want to create an…

amiry jd
- 27,021
- 30
- 116
- 215
3
votes
1 answer
How to get the request body inside InvalidModelStateResponseFactory?
I have an API that is called by an external application, and I believe we're having a lot of 400 errors.
I've looked up how to catch and log automatic HTTP 400 errors, and found this solution:
services.AddMvc()
…

Paul Karam
- 4,052
- 8
- 30
- 53
3
votes
1 answer
Why ModelState returns different result and how to fix it?
Asp.net core 3.1 WebApi.
I have a model with required properties.
1.If model is not valid, then the response contains data
like :
{
"errors": {
"Name": [
"Update model can't have all properties as null."
],
…

Artem A
- 2,154
- 2
- 23
- 30
3
votes
2 answers
How to add images in validation summary along with the error message?
I wanna display error message with success image(green tick mark) and failure image(Red warning) in validation summary. how to do this.
and i validation summary i will have to display some text in bold, italics etc. for that i tried to pass string…

nimi
- 5,359
- 16
- 58
- 90
3
votes
3 answers
Copy ModelState Errors to TempData & Display them In the view
Most of my action methods return PartialViews on success and RedirectToAction results on failure. For that, I would like to copy the model state errors into TempData so I could display them to the user. I've read several questions here on SO and…

Kassem
- 8,116
- 17
- 75
- 116
3
votes
0 answers
Process ModelState errors from WebAPI Blazor (server-side) call
When I am making a WebAPI call I want to find out how to pass back ModelState errors to my Blazor application.
The DataAnnotations all validate correctly but, if I do any other types of validation (once past the ModelState.IsValid call), I can't get…

Rabbitslayer
- 127
- 2
- 7
3
votes
1 answer
To pass a model State error to a different Action Method
I have an action method as below :
[HttpPost]
public ActionResult Edit(EditViewModel model)
{
if (ModelState.IsValid)
{
//Do Something
}
var model1 = new IndexViewModel();
ModelState.AddModelError("", "An…

TheFallenOne
- 1,598
- 2
- 23
- 57
3
votes
1 answer
.NET Core DateTime? field ModelState is invalid if null
I have a field declared in my model:
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? dataCreazione { get; set; }
in the view i render the field with…

Diego
- 31
- 4
3
votes
1 answer
How can I intercept FluentValidation error response so I can format it to my standard
I am working on an ASP.NET Core 2.1 API that currently has a global ValidateModelAttribute filter that intercepts the context.ModelState in the OnActionExecuting method so it can format any modelstate errors to match the project design standard for…

whiskytangofoxtrot
- 927
- 1
- 13
- 41
3
votes
1 answer
ModelState.IsValid is always true while using Data annotation, MVC as Web API
I have seen many questions like this one but no answer has solved my problem.
I can submit a name that contains a space, or leaving a description field empty and the ModelState is still valid.
in my StartUp.cs I do use
services.AddMvc();
I did try…

freddoo
- 6,770
- 2
- 29
- 39