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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:11:51+00:00 2026-06-15T22:11:51+00:00

I have a view model that contains enum with nullable type like this one

  • 0

I have a view model that contains enum with nullable type like this one :

public StudyLevel? studyLevel { get; set; }

I have made custom html helper to display a dropdownlist for rendering the enum into the view, the nullable case is displayed using

<option value="null">No value</option>

the problem is that when i submit the form modelstate give me the error :

studylevel cannot be "null" .

Could you suggest me any way to help me handle the nullable type in the view ?

  • 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-15T22:11:53+00:00Added an answer on June 15, 2026 at 10:11 pm

    What if you change your html helper to display the null value like this?

    <option>No value</option>
    

    Or like this?

    <option value="">No value</option>
    

    Edit: A better option (IMO) is to create a collection of SelectListItem and then use a built-in HTML helper. Please take a look into this article I created some months ago, it may help you. You can use it like this:

    @Html.EnumDropDownList<StudyLevel?>("studyLevel", "No value")
    

    More info here:

    ASP.NET MVC: Creating localized DropDownLists for enums

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

Sidebar

Related Questions

I have a view model that looks like this public class ViewModelRound2 { public
I have an MVC view model that looks like this: public class DirectorySearchModel {
I have a view model that contains a Product class type and an IEnumerable<
I have a model that looks something like this: public class SampleModel { public
I have a view model that contains user details and also extended user details
I have an enum for one of the properties of my view-model. I want
I have a view model that implements IValidatableObject that contains a string and a
I have a model that contains a collection, such as this: class MyModel {
I have a view model that contains a fill object and an rx object.
I have a Picture model that contains a variable for a view count (integer).

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.