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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:03:28+00:00 2026-06-08T01:03:28+00:00

Using this model: public class Cases { //case data model for call center //implement

  • 0

Using this model:

public class Cases
    {
    //case data model for call center
    //implement lists for all related child tables too

    [Key]
    public int CasesID { get; set; }

    public string CaseNumber { get; set; }

    [Required(ErrorMessage = "Customer is Required")]
    public int CustomerID { get; set; }
    public virtual Customer Customer { get; set; }

    [MaxLength(50)]
    public string UserName { get; set; }  //get user name from the aspnet membership

    [Required(ErrorMessage = "Case Category is Required")]
    public int CaseCategoryID { get; set; }

    [Required(ErrorMessage = "Technician is Required")]
    public int TechnicianID { get; set; }
    public virtual Technician Technicians { get; set; }

    [Required(ErrorMessage = "Engine Model is Required")]
    public int EngineModelID { get; set; }
    public virtual EngineModel EngineModel { get; set; }

    [MaxLength(50)]
    public string BMSWorkorder { get; set; }

    [MaxLength(50)]
    [Required(ErrorMessage = "Status is Required")]
    public string CaseStatus { get; set; }

    [MaxLength(50)]
    public string OpenedBy { get; set; }

    [Required(ErrorMessage = "Opened Date is Required")]
    [DataType(DataType.DateTime)]
    public DateTime? OpenedDate { get; set; }

    [MaxLength(50)]
    public string ClosedBy { get; set; }

    [DataType(DataType.DateTime)]
    public DateTime? ClosedDate { get; set; }

    [MaxLength(50)]
    [Required(ErrorMessage="Caller First Name is Required")]
    public string CallerFirstName { get; set; }

    [MaxLength(50)]
    [Required(ErrorMessage = "Caller Last Name is Required")]
    public string CallerLastName { get; set; }

    [MaxLength(100)]
    public string AdditionalContact { get; set; }

    [MaxLength(10)]
    [Required(ErrorMessage = "Qualified is Required")]
    public string Qualified { get; set; }

    public string Description { get; set; }

    [MaxLength(50)]
    [Required(ErrorMessage = "ESN is Required")]
    public string ESN { get; set; }

    [MaxLength(50)]
    [Required(ErrorMessage = "Mileage is Required")]
    public string Mileage { get; set; }

    [DataType(DataType.Date)]
    public DateTime? DateInService { get; set; }

    [MaxLength(50)]
    public string ESTR { get; set; }

    [MaxLength(50)]
    [Required(ErrorMessage = "EDS is Required")]
    public string EDS { get; set; }

    [MaxLength(50)]
    public string GensetSerialNumber { get; set; }

    [MaxLength(50)]
    public string GensetModelNumber { get; set; }

    //child Case Notes records
    public virtual ICollection<CaseNotes> CaseNotes { get; set; }

    //child case attachment records
    public virtual ICollection<Attachment> Attachments { get; set; }

    //child case complaint records
    public virtual ICollection<CaseComplaint> CaseComplaint { get; set; }

    //tracking fields
    public DateTime? CreatedOn { get; set; }
    [MaxLength(50)]
    public string CreatedBy { get; set; }
    public DateTime? ModifiedOn { get; set; }
    [MaxLength(50)]
    public string ModifiedBy { get; set; }
    }

I am wondering why even though only some of the properties are marked required, the modelstate does not get set valid unless all properties have values when saving.

Am I doing something wrong?

EDIT

Here are my razor elements for the dropdownlist fields in question:

@Html.DropDownList("Qualified", String.Empty)
@Html.ValidationMessageFor(model => model.Qualified)

@Html.DropDownList("EngineModelID", String.Empty)
@Html.ValidationMessageFor(model => model.EngineModelID)

@Html.DropDownList("CaseCategoryID", String.Empty)
@Html.ValidationMessageFor(model => model.CaseCategoryID)
  • 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-08T01:03:30+00:00Added an answer on June 8, 2026 at 1:03 am

    The EngineModelID and CaseCategoryID properties must be nullable integers on your view model if you want to allow empty values. Oooops, you are not using view models.

    ASP.NET MVC automatically makes non-nullable types required. You could disable this explicitly in your Application_Start:

    DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
    

    But if you want to do the things properly you should use view models.

    The following is absolutely horrible:

    @Html.DropDownList("CaseCategoryID", String.Empty)
    

    I guess you have stuffed a SelectList in a ViewBag.CaseCategoryID so the CaseCategoryID does 2 things at the same time: it represents a list and a selected scalar value.

    With view models you would use the strongly typed version of those helpers:

    @Html.DropDownListFor(x => x.CaseCategoryID, Model.CaseCategories)
    

    where CaseCategories will be an IEnumerable<SelectListItem> property on your view model that the controller would populate.

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

Sidebar

Related Questions

I'm using MVC3 and I have a model like this: public class Foo {
When using this object model: interface IInterface {} class Impl : IInterface { public
I'm using FluentNHibernate but NHibernate XML will do. Say I have this model public
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
I want to exclude a field using Dozer like this : <mapping> <class-a>com.core.model.Model</class-a> <class-b>com.core.model.ModelIS</class-b>
Let's say you have this Model: //model public class Stuff { public string Name
I am using http://nvie.com/posts/a-successful-git-branching-model/ As far as I understand, main repo in this model
This the model that I want to create using json file Ext.define('Users', { extend:
I have this view @model IEnumerable<ViewModelRound2> ... <snip> ... @{ using (Html.BeginForm(new { round1Ring3Bids
This is my model of my asp.net mvc 2 project : using System; using

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.