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
0
votes
1 answer
Include a valid field if ModelState state is Invalid
In ASP.NET Web API I want to include a valid field when returning errors to the caller.
public class User
{
[Required(ErrorMessage = "ThirdPartyID is required!")]
public int ThirdPartyID { get; set; }
[Required(ErrorMessage =…

tom
- 1,822
- 4
- 25
- 43
0
votes
2 answers
How to load model errors into modal dialog
is it possible to load the modelstate errors to the same modal dialog after submitting a form with javascript?
My code is something like this:
Controller:
public ActionResult Create(MyModel model){
if(ModelState.isValid){
// DB Save
…

Flavio
- 73
- 3
- 11
0
votes
3 answers
MVC3 View Update Issue
Here is a action which sets up the images to ViewBag for display.
public ActionResult UploadPhoto()
{
List images = new List();
foreach (var file in…

NaveenBhat
- 3,248
- 4
- 35
- 48
0
votes
0 answers
ModelState Clear, Remove an array item, TryValidateModel
My model has some property, one of them is Array of Class, and for some Property in Model and array class use from datannotation attribute. In view user fill some row as array and other model property, and may delete some of row(arrayProperty), me…

Mohammad Akbari
- 4,486
- 6
- 43
- 74
0
votes
2 answers
Require property if parent class is required
I have a problem with MVC3 model validation and DataAnnotations
I have the following classes:
public class A
{
public C SomeProperty {get;set;}
}
public class B
{
[Required]
public C SomeProperty {get;set;}
}
public class C
{
…

Erik Nordenhök
- 645
- 1
- 5
- 14
0
votes
1 answer
MVC ModelState erroneously reports errors
I am receiving a model from a view.
Some of the values are automatically filled in.
However, some of the required values need to be added manually, like so:
[HttpPost]
public ActionResult Foobar(FooModel model, FormCollection collection)
{
//…

Yehuda Shapira
- 8,460
- 5
- 44
- 66
0
votes
1 answer
Add ModelStateError without ViewModelClass.ModelClass annotation
I have created a special viewmodel class for my model, for adding data that is to be computed into the model, like some int for time
public class SessionView
{
public Session Session { get; set; }
public int StartHour { get; set; }
…

Erik Karlsson
- 570
- 1
- 6
- 17
0
votes
1 answer
MVC ModelState and Collections
I have a problem i am trying to solve.
I have a grid (tabular) type layout that will contain a collection of ViewModels.
I want to be able to validate those ViewModels and then turn the cells for a given property red if it contains error:
Prop…

Sam
- 15,336
- 25
- 85
- 148
0
votes
1 answer
Manipulating other elements when ModelState is not valid
Is it possible to change the class on another element when !ModelState.IsValid?
My view, simplified below, will have
wrapped around each field
@using(Html.BeginForm("AddRole","Admin", FormMethod.Post, new { @class =…

bflemi3
- 6,698
- 20
- 88
- 155
0
votes
1 answer
ModelState and Dialog Boxes
I have a dialog box that uses the Entity foo.
After I save the values from this dialog box I do the following :
$('#SaveEditPQ').submit(); //jquery submit
$("#NewQuickDlg.results").remove(); // clear the fields within the dialog Box
…

Mihai Labo
- 1,082
- 2
- 16
- 40
0
votes
1 answer
MVC3 passing incorrectly formatted datetime to Controller but correcting it in the Controller action gives ModelState error
Am I the only one having this problem or I am doing it in totally wrong direction.
I have a View passing DateTime value:
@Html.Label("Appointment date", null, new { @class = "control-label" })
…

JofryHS
- 5,804
- 2
- 32
- 39
0
votes
1 answer
Required ModelValidation just for new objects ASP.NET MVC
I have this issue since yesterday.
In my User model I have a [NotMapped] called "ConfirmPassword". I don´t save it on the database but I use it on my Create form as a always to validate the data input for new users.
Since than, it´s ok. The problem…

paulofabiano
- 3
- 3
0
votes
1 answer
How to add ModelStateDictionary in Code?
I am developing the MVC app.
I am trying to validate control but cant see ModelState.AddRuleViolations property how to add ref ?
I have already added System.Web.Mvc library in class.
but cant see the ModelStateDictionary.

nilesh1foru
- 57
- 2
- 9
0
votes
1 answer
Unable to post a form due to ValidationSummary errors on form fields that are hidden dynamically through javaScript.
ASP.NET MVC 3 application.
I am trying to post form that has some dynamic fields which appear and disappear using JavaScript. I am using IValidatableObject for doing server side validation on some of these dynamic fields.
When these fields are…

Kanav Punj
- 1
- 1
0
votes
1 answer
Is manipulating the ModelState in this way a coding mispractice?
I am presented with a situation where I would like to use Html.ValidationSummary() in my views to display a generic error message. Maybe something like "There was a problem with the information you entered." but without getting a list of every…

Jesse Hallam
- 6,794
- 8
- 48
- 70