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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:12:04+00:00 2026-05-15T20:12:04+00:00

I understand that a ModelBinder is a good place to do work on the

  • 0

I understand that a ModelBinder is a good place to do work on the request so that you keep that type of code out of the controller. Working with Form Values would be an example. That seems to makes sense however, I inherited an application that is using a Custom Binder and I just can’t seem to figure out how or why it works.

The binder itself exists to deal with only TimeZoneInfo objects as they (Time Zones) are used within the application so it is registered in the Application_Start method in the global like so:

  binders.Add(new System.Collections.Generic.KeyValuePair<Type, IModelBinder>(typeof(TimeZoneInfo), new TimeZoneInfoModelBinder()));

Where binders is of type ModelBinderDictionary. The binder itself then looks like this:

public class TimeZoneInfoModelBinder : DefaultModelBinder
{
    public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        if (bindingContext == null)
        {
            throw new ArgumentNullException("bindingContext");
        }
        string tzId = bindingContext.ValueProvider.GetValue(bindingContext.ModelName).AttemptedValue;


        try
        {
            return TimeZoneInfo.FindSystemTimeZoneById(tzId);
        }
        catch (Exception ex)
        {
            bindingContext.ModelState.AddModelError(bindingContext.ModelName, ex);
        }
        return null;
    }
}

Now from stepping through the code I know this Binder is only called when I POST data back to the server that involves a particular Model which has a TimeZoneInfo property on it. My assumptions are:

  • The runtime “knows” about all of the models and only invokes the custom binder when it finds a property with the same type as the one that was passed in to the binder.
  • The reason this is being done is because the TimeZoneInfo type is a complex type and, therefore, can’t be implicitly converted to from a string (POST data)

Is this a correct understanding of this particular instance or am I missing something?

Thanks!

  • 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-15T20:12:05+00:00Added an answer on May 15, 2026 at 8:12 pm

    You’re close…

    The model binder considers all of the data from the request’s form data, the URL query string, and routing parameters. The binder will attempt to bind to the arguments of the action method and to any public properties of the model that have both a get and set defined. This is done by considering the name of the parameter and/or public property.

    Since all of the input sources are in a name-value format, the names are matched. For example, if there is an “id” routing parameter and your action method has an “id” argument in its signature, the binder will bind the routing parameter to that action method argument. If there is a country form field and a model with a public country property, the model binder will attempt to bind the form field to the model. Etc.

    The binder considers the type of the property when binding. The default model binder knows how to bind to the scalar properties (int, decimal, DateTime, etc.). It also can bind to a list (key format MyList[0]) or to a complex type that in turn exposes child properties (e.g, key format Rectangle.Width).

    The example you have posted adds the ability to bind to a TimeZoneInfo object. That binder is being invoked because the name of a form parameter, query argument or routing parameter matches the name of a public property on your model that exposes a getter and setter that returns a TimeZoneInfo object.

    Note the ModelBinder works in concert with the ModelState dictionary. It’s important that invalid user input gets preserved even if it cannot be converted to the target type. In that case, an error is added to the ModelState dictionary and the raw value of the input parameter is kept so that it can be included in a re-rendering of the form with validation errors.

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

Sidebar

Related Questions

I understand that every time I type the string literal , the same String
I understand that NSNumber cannot go beyond 1/10ths place. What can I use as
I understand that certain data type object have certain buffer size. E.g. a char
I understand that it's not possible request JSON data from a remote domain due
I understand that some countries have laws regarding website accessibility. In general, what are
I understand that there are several ways to blend XNA and WPF within the
I understand that they are both supposed to be small, but what are the
I understand that Microsoft uses this template when versioning their products: Major.Minor.Build.Revision. Major is
I understand that server-side validation is an absolute must to prevent malicious users (or
I understand that IronPython is an implementation of Python on the .NET platform just

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.