Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8413233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:52:41+00:00 2026-06-10T00:52:41+00:00

I am posting a form in an asp.net-mvc page. Here is my controller action:

  • 0

I am posting a form in an asp.net-mvc page. Here is my controller action:

    public ActionResult UpdateData(MyFormObject entity)
    {
        bool isValid = IsValid(entity);

        if (!isValid)
        {
            var firstError = ModelState.Values.SelectMany(v => v.Errors).First();
            throw new HttpException(404, firstError.ErrorMessage);
        }
        return Json(BuildResult(entity));
    }

Even thought the post passes all of my explicit validation logic, when i check ModelState I see errors. I am seeing errors in ModelState when any of my properties are empty. Here is my object:

public class MyFormObject 
{
    public int Id{ get; set; }
    public int TestId{ get; set; }
    public int OtherId{ get; set; }
}

and I am looking at Model.State and i see errors for any element in my object that is not populated.

If I change this to (NOTE: the “?”)

public class MyFormObject 
{
    public int? Id{ get; set; }
    public int? TestId{ get; set; }
    public int? OtherId{ get; set; }
}

then i no longer get any errors. Is there some default validation that is happening here that I am not setting. I am trying to figure out what is setting ModelState errors in the first case above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:52:42+00:00Added an answer on June 10, 2026 at 12:52 am

    As @Maxim V. Pavlov said, when you post, ASP.MVC engine will try to validate the model, ie its class, and based on class you cited as example, the properties don’t accepts a null or empty value, then it will throw an exception and ModelState will be invalid.

    You can see more here @ Validating Model Data in an MVC Application and here ModelStateDictionary.IsValid Property

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In ASP.NET MVC, I have a main standard form that posts to an action,
I am posting a json object to an ASP.Net MVC controller with C# code.
I am using asp.net MVC and I am having an issue posting a form
i want to override the default asp.net-mvc validation when posting a form so i
I've got a regular ASP.NET web form page and am pasting in a <%=
so i've got an array of numbers that i'm posting to an asp.net mvc
When posting a form in ASP.NET, it adds container information to the request form
I have a nested form in an asp.net page. This nested form is a
Here's the situation... Site 1) ASP.NET MVC application for customers to login, view and
I am using asp.net's modelbinder functionality to bind form values to my entity when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.