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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:58:02+00:00 2026-06-17T21:58:02+00:00

I successfully made Enum binder and from what iv tested, everything works. But i

  • 0

I successfully made Enum binder and from what iv tested, everything works. But i want to have nullable enum parameter in my controller and when i change to nullable, my binder dont work.

 public class EnumBinder<T> : IModelBinder
    {
        private object DefaultValue { get; set; }
        public EnumBinder(object defaultValue)
        {
            DefaultValue = defaultValue;
        }


        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var result = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);

            if(result == null || string.IsNullOrEmpty(result.AttemptedValue))
            {
                return DefaultValue;
            }

            return GetEnumValue<T>(result.AttemptedValue);
        }



        public static object GetEnumValue<T>(string value)
        {
            var enums = Enum.GetValues(typeof (T)).Cast<T>().ToList();

            foreach (var e in enums)
            {
                var _enum = Enum.Parse(typeof (T), e.ToString());
                if (string.Equals(value, _enum.ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    return _enum;
                }
            }

            return null;
        }

    }

Works on

 public virtual ActionResult ControllerName(Status status)
    {
       return View();
    }

but dont work on

 public virtual ActionResult ControllerName(Status? status)
    {
       return View();
    }

Of course i have registered my binder on application start

ModelBinders.Binders.Add(typeof(CallStatus), new EnumBinder<CallStatus>(null));

What i do wrong, why i cant return nullable enum in my controller?

  • 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-17T21:58:04+00:00Added an answer on June 17, 2026 at 9:58 pm

    CallStatus and CallStatus? are different types. The ? is syntactic sugar; CallStatus? is actually type System.Nullable<CallStatus>.

    You need to either add another binder for typeof(Nullable<CallStatus>), or use a provider, as described here.

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

Sidebar

Related Questions

i have made my custom Static Library (.a) successfully. i have tested it in
I have successfully made a custom control-slider, but it's not draggable. I tried searching
I have successfully made an facebook application which shows real time data from facebook
I have successfully made an application but whenever I try installing it in the
I have repo the Android source code from http://source.android.com/ . And successfully made a
I have successfully made an app that sends a request from my Windows Phone
I'm using Pex and Moles 0.94.51023.0 with VS2010 SP1. I have successfully made some
I have successfully made contact with the internet and parsed a few documents via
So I have successfully made a ray the represents the mouse unprojected into the
I have successfully made a very simple LevelHelper/Box2D/Cocos2D project. I am now trying to

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.