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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:15:27+00:00 2026-05-21T10:15:27+00:00

I have a custom struct called TimeOfDay which is used in a view model

  • 0

I have a custom struct called TimeOfDay which is used in a view model like this:

public class MyViewModel
{
  public TimeOfDay TimeOfDay { get; set; }
}

I have created a custom model binder called TimeOfDayModelBinder and registered it in Global.asax.cs like this:

ModelBinders.Binders.Add(typeof(TimeOfDay), new TimeOfDayModelBinder());

And everything works great. However, if I change my view model to this:

public class MyViewModel
{
  public TimeOfDay? TimeOfDay { get; set; } // Now nullable!
}

My custom model binder is no longer called. I know that the property is no longer a type of TimeOfDay, but a Nullable which is different. So does this mean I should add my custom model binder twice in Global.asax.cs like this:

ModelBinders.Binders.Add(typeof(TimeOfDay), new TimeOfDayModelBinder());
ModelBinders.Binders.Add(typeof(TimeOfDay?), new TimeOfDayModelBinder());

It works, but there’s just something I don’t like about it. Is this really necessary to handle my type as nullable, or is there something I’m missing?

  • 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-21T10:15:28+00:00Added an answer on May 21, 2026 at 10:15 am

    Per @LukeH’s comment, it seems it is necessary. I guess that makes sense too, as TimeOfDay and Nullable<TimeOfDay> really is two different types in the CLR. So I guess I have to live with it. 🙂

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

Sidebar

Related Questions

I have a custom c# type like (just an example): public class MyVector {
I have a custom struct : struct A { public int y; } a
I have a function which takes a custom struct as the argument. how can
I have a listbox bound to a view model observable collection: This works fine,
I have a multithreaded application that runs using a custom thread pool class. The
I have a vector of custom Struct that needs to be sorted on different
I have a problem putting data into an unordered_map using a struct as key:
Extends . I have: struct Coord { int row, col ; bool operator<( const
I currently have a menu with subitems that is being stored in this dictionary
I'm having some trouble with a linq query. It's a simple problem, but I'm

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.