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 235891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:18:05+00:00 2026-05-11T20:18:05+00:00

On the NerdDinner example of Professional ASP.NET MVC 1.0 there’s a method to create

  • 0

On the NerdDinner example of Professional ASP.NET MVC 1.0 there’s a method to create a new dinner as copied bellow (page 89 of the free NerdDinner version).

There it checks ModelState.IsValid for true. It seems to check if the model is valid for the database (that is, it catches data type conversions, like dates with invalid format, but not business rules). Is that true?

When submitting the form, if you have an error in the date, ModelState.IsValid will be false and you’ll get back an error, but only for the date because AddRuleViolations was never executed. If you remove the check for ModelState.IsValid completely, then you’ll get all the errors (due to the exception), including a marking in the date when it is invalid. Then, why is the check for ModelState.IsValid there at all? Am I missing something?

// 
// POST: /Dinners/Create 

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Create(Dinner dinner) {
    if (ModelState.IsValid) {
        try {
            dinner.HostedBy = "SomeUser"; 

            dinnerRepository.Add(dinner);
            dinnerRepository.Save();

            return RedirectToAction("Details", new {id = dinner.DinnerID }); 
        } catch {
            ModelState.AddRuleViolations(dinner.GetRuleViolations());
        } 
    } 
    return View(dinner); 
} 
  • 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-05-11T20:18:05+00:00Added an answer on May 11, 2026 at 8:18 pm

    ModelState.IsValid tells you if any model errors have been added to ModelState.

    The default model binder will add some errors for basic type conversion issues (for example, passing a non-number for something which is an “int”). You can populate ModelState more fully based on whatever validation system you’re using.

    The sample DataAnnotations model binder will fill model state with validation errors taken from the DataAnnotations attributes on your model.

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

Sidebar

Related Questions

i am reading the professional asp.net mvc book and implement the nerd Dinner example
I'm working through the NerdDinner ASP.NET MVC 1.0 example. I have it all working
Working through a tutorial (Professional ASP.NET MVC - Nerd Dinner), I came across this
I'm trying to go through the NerdDinner example chapter from the ASP.Net MVC 1.0
I have an ASP.NET MVC application that is calendar-like. As per the NerdDinner example,
First time using Asp.net-mvc and originally followed the NerdDinner tutorial. My form submit button
I am following the Nerd Dinner tutorial as I'm learning ASP.NET MVC, and I
I'm following a tutorial on creating the NerdDinner using ASP.Net MVC. However, I'm using
I'm currently going through the ASP.NET MVC NerdDinner tutorial and am having a problem
I'm starting with ASP.NET MVC, and working with NerdDinner as reference. I did the

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.