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

  • Home
  • SEARCH
  • 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 7417475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:42:35+00:00 2026-05-29T07:42:35+00:00

Using ASP.NET MVC when I create my model, then a controller based on the

  • 0

Using ASP.NET MVC when I create my model, then a controller based on the model with CRUD operations, the CRUD views are generated. I added some code using Fluent API to require certain fields but for some reason the ModelState.IsValid passes even when these fields are not completed. What determines whether this passes or not? I thought it was based on your model property data types and other things like being required or maxlength, etc….

Also, I have manually added code to grab a list of Categories from the database and generate a checkbox for each one in the View. This is a navigation property for the Project model where there is a many-many relationship. To get the group of checked values in the Create(Project project) method in the controller I use:

var selected = Request["categories"].Split(',');

This however, throws the classic Object reference not set to an instance of an object error if no values are checked. So what I want to know is, how can I determine that this does not have any values so I can do something else once detected?

  • 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-29T07:42:36+00:00Added an answer on May 29, 2026 at 7:42 am

    I added some code using Fluent API to require certain fields but for
    some reason the ModelState.IsValid passes even when these fields are
    not completed.

    ASP.NET MVC doesn’t know anything about the Fluent API of Entity Framework and doesn’t evaluate this configuration. You only can use the data annotations which MVC will recognize:

    [Required]
    public string SomeProperty { get; set; }
    

    …how can I determine that this does not have any values so I can do
    something else once detected?

    Not sure if I understand it correctly but I’d say:

    var categories = Request["categories"];
    if (categories != null)
    {
        var selected = categories.Split(',');
        // ...
    }
    else
    {
        // do something else
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ASP.Net MVC along with Jquery to create a page which contains
I need to create a web application using ASP.NET MVC, jQuery and web standards
Say you create a form using ASP.NET MVC that has a dynamic number of
what is the preferred practice when linq2sql using (in asp.net mvc applications): to create
I am using FckEditor in Create.aspx page in asp.net mvc application. Since I need
I am trying to create a custom authentication scheme in ASP.NET MVC using form
I'm using ASP.NET MVC and I have a model class which represents a peice
I'm using VS2010, ASP.NET MVC 2, and ReSharper 5.0. When I create a new
I am using asp.net mvc for an application. I've taken some guidance from Rob
I am converting an application I created using webforms to the asp.net mvc framework

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.