Questions tagged [modelstate]

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.

497 questions
0
votes
2 answers

How can I disable a textbox if there are modelstate errors in mvc?

I am doing some server stuff that could potentially fail (not likely) but something can go wrong. I want to stop the user from going any further so I want to disable the input so that they have to refresh the page. How can I disable it based on…
Pittfall
  • 2,751
  • 6
  • 32
  • 61
0
votes
1 answer

ASP.NET MVC DataAnnotations StringLength On Password ModelState.IsValid Fails When Hashed

First question is, using StringLength, is it possible to specify only a minimum length? More importantly, this is what I have for a password. private string password; [Required] [DataType(DataType.Password)] [StringLength(15, MinimumLength =…
Shane LeBlanc
  • 2,633
  • 13
  • 42
  • 74
0
votes
1 answer

asp.net mvc how to launch validation of a object before rendering

I use ASP.NET MVC 2, with Visual Studio 2008 and my view is strongly-typed. The validation using ValidationAnnotation works. What I'm trying to find is how to launch the validation when opening the form. When it opens the model has error, but error…
fanfaron
  • 31
  • 8
-1
votes
1 answer

Logging the model data from the POST request body

My requirement is to log the model data that I am receiving from a POST request. but when I am tring to get the values from ModelState.Values, I am not receiving anything. I also tried to Log Request body, but same with the request body also, I am…
-1
votes
1 answer

ASP.NET MVC - DB EntityValidation and Model State conflict

I have model class which consist of 3 required field. I am submitting MVC form with only 2 required fields and keeping one field blank (PhoneNumber). public class User { [Required] public String UserName { get; set; } [Required] …
SSD
  • 1,041
  • 3
  • 19
  • 39
-1
votes
1 answer

Regex data annotation making model state invalid ASP.NET Core

I have a simple regex data annotation [RegularExpression(@"\d{5}", ErrorMessage = "Zipcode must be exactly 5 digits")] public string Zipcode { get;set; } When the value of the Zipcode is "12345" Model.IsValid returns false.
Ajay S
  • 54
  • 5
-1
votes
2 answers

ASP.NET Core 3.0 form ModelState always invalid

I am in the process of porting an older ASP.NET 4.5 website to ASP.NET Core 3.0, and am running into some issues with the identity Razor pages and how they work. For example, on the registration page of the application, as shown below, the form is…
dinotom
  • 4,990
  • 16
  • 71
  • 139
-1
votes
2 answers

How to test a automatic ModelState's custom attribute method validation for Core api controller?

I would like to test my controller method for a given MyModelDTO values. This is my controller Post method (simplified): [HttpPost] public ActionResult Post([FromBody] MyModelDTO itemDTO) { …
Shahar Shokrani
  • 7,598
  • 9
  • 48
  • 91
-1
votes
1 answer

Adding values to model and passing trough ModelState vaidation

I am trying to understand what would be the best approach to my problem. Let's say I have a model like this: public class Customer { [Key] public int Id { get; set; } public string Name { get; set; } [Required] public int StoreId {…
-1
votes
1 answer

ModelState does not contains AddModelError()

I was working with a ModelState.AddModelError() recently. But there is a problem. I have 2 files in one when I type ModelState. intellisense shows the AddModelError() method. But in other file its not. I am getting the error there.…
Area51
  • 3
  • 3
-1
votes
1 answer

Model state.isvalid always return true

I am a new in MVC Programming in asp.net.I created application in mvc4 with entity framework.My problem is that i can't validate input entry.It always return true .My index.aspx code here <% using (Html.BeginForm("Validate","Transport")){%> …
-1
votes
1 answer

ModelState is false with EditorTemplate

This is my Model public class LoginModel { [UIHint("string")] [Required] [Display(Name = "User name")] public string UserName { get; set; } [Required] [DataType(DataType.Password)] [Display(Name = "Password")] public…
JKANNAN
  • 83
  • 1
  • 10
-1
votes
1 answer

Forwarding ModelState error message while using RedirectToAction

In the Post method of my controller's function I have added some ModelStateError. Once added I Redirect to the Get method. In Get method when I return the view, I want to be able to fetch the error message passed from Post method and add it to…
Cybercop
  • 8,475
  • 21
  • 75
  • 135
-1
votes
2 answers

ModelState binding custom array of checkboxes

ViewModel Binding is working, the object passed back to the edit controller contains the correct values, which is a list of selected options. However, ModelState binding is not working, the model state AttemptedValues exist, but aren't being…
Lee Louviere
  • 5,162
  • 30
  • 54
-2
votes
1 answer

Is there any way to check ModelState.IsValid on page load BEFORE the form is submitted?

So we added a required field to our form that our users submit and are able to edit. So if a user were to open their form to edit it, there would be a new required field, which works fine. If you try to submit the form, a model error displays saying…
Daath
  • 1,899
  • 7
  • 26
  • 42
1 2 3
33
34