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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:51:17+00:00 2026-05-30T04:51:17+00:00

How can I treat a Nullable just like I do with Enum within the

  • 0

How can I treat a Nullable just like I do with Enum within the String.cshtml file?


Background:
I have successfully implemented a custom Editor Template for my enums (implementing the String.cshtml within the Views/Shared/EditorTemplates/String.cshtml.

I understood that it works as a fallback type for Enums, so whenever you have

Html.EditorFor(m => m.PropertyOfTypeEnum)

It creates my correcly a dropdown in which I can select the options.

Problem: the issue arises when my PropertyOfTypeEnum is a Nullable<>.
I don’t understand exactly why, it does not fall back into the String.cshtml and therefore I can’t treat it to render my dropdown list.

Further Info: I have double checked to see and it’s actually NOT hitting my breakpoint at my String.cshtml.

Does anyone have any idea of how to treat it?

  • 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-30T04:51:18+00:00Added an answer on May 30, 2026 at 4:51 am

    I am guessing that it is not working because calling ToString() on a null object would fail, therefore it is not able to infer to use String.cshtml by looking at the data type (which is null Enum and not null string).

    You can help your editor template along by specifying that it should be used:
    Add [UIHint("String")] in your view model for the required enum property.

    Alternative solution:
    I had to solve the same problem but used a different technique. I added an additional extension method for DropDownFor that understand enums. For example:

    public static MvcHtmlString DropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression) 
                   where TProperty : struct
    {
                IEnumerable<SelectListItem> selectList = DropDownHelper.ToSelectListItems<TProperty>();
                return htmlHelper.DropDownListFor(expression, selectList);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just thinking, as you can treat Blocks like objects if I create
I do like the way I can treat lists in Python. It does any
CakePHP1.3 with SimpleTest can't treat enum type column. How to resolve this problem.? Notice:
How can I treat the last element of the input specially, when iterating with
I'm a little confused between a unichar and a char. Can I treat unichar's
It's not that I can't google for myself, however others have tread this path
Can you cast a List<int> to List<string> somehow? I know I could loop through
Can anyone tell me how I can display a status message like 12 seconds
I would like to treat a database query as a standard C++ input iterator.
I have an application which generates PDFs. Now I'm using Apache FOP just for

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.