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

  • Home
  • SEARCH
  • 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 6131623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:59:54+00:00 2026-05-23T16:59:54+00:00

I have a custom binding of objects array into IEnumerable bookings in a controller

  • 0

I have a custom binding of objects array into IEnumerable bookings in a controller action

HTML:

<input class='textBox' name='bookings[0].Date' type='text' value='01/01/2001' />
<select name='bookings[0].StartTime' class='startTime'>
  <option value="7">7:00</option>
  <option value="7.5">7:30</option>
  <option value="8">8:00</option>
  <option value="8.5">8:30</option> 
</select>
<select name='bookings[0].EndTime' class='endTime'>
  <option value="7">7:00</option>
  <option value="7.5">7:30</option>
  <option value="8">8:00</option>
  <option value="8.5">8:30</option> 
</select>
....
<input class='textBox' name='bookings[5].Date' type='text' value='01/01/2001' />
<select name='bookings[5].StartTime' class='startTime'>
<select name='bookings[5].EndTime' class='endTime'>

Controller action:

public ActionResult CreateEvent(IEnumerable<BookingDetails> bookings)
{
  ....
}

And container class for binding

public class BookingDetails
{
    public string Date { get; set; }
    public float StartTime { get; set; }
    public float EndTime { get; set; }
}

“bookings” collection of controller action parameter contains data absolutely properly if culture of the page is en-US but if it is “fr-FR” floating values for time come as 0.
ex:

— Date: 1/1/2001
– StartTime: 0
– EndTime: 10
— Date: 1/1/2001
– StartTime: 11
– EndTime: 0

where 0 appears decimal value was selected: 8.5 or 12.5 for example.
I can’t have values with comma and period for different cultures because of sophisticated javascript calculation on the page which supports only period for floating numbers.

Does anybody know a workaround to send data to the controller with “invariant” culture type?
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-23T16:59:54+00:00Added an answer on May 23, 2026 at 4:59 pm

    you can create a custom modelbinder for float values only like

    public class DecimalModelBinder : IModelBinder
        {
            public object BindModel(ControllerContext controllerContext,
                ModelBindingContext bindingContext)
            {
                ValueProviderResult valueResult = bindingContext.ValueProvider
                    .GetValue(bindingContext.ModelName);
                ModelState modelState = new ModelState { Value = valueResult };
                object actualValue = null;
                try
                {
                    actualValue = Convert.ToDecimal(valueResult.AttemptedValue,
                        CultureInfo.InvariantCulture);
                }
                catch (FormatException e)
                {
                    modelState.Errors.Add(e);
                }
    
                bindingContext.ModelState.Add(bindingContext.ModelName, modelState);
                return actualValue;
            }
        }
    

    and then you can register it in global.asax in Application_Start

    ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder());
    

    For code sample and detail explanation have a look at phil haack’s post. I have just changed the Culture to invariant culture when calling Convert.ToDecimal

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

Sidebar

Related Questions

I have an custom binding defined as follows: <customBinding> <binding name=binaryHttpBinding> <binaryMessageEncoding /> <httpTransport
I have custom objects I am binding to using ObjectDataSource. I have three-level binding:
I have a list of custom objects: say Fruits with two string properties Name
I have the GridView below. I am binding to a custom datasource in the
I have a helper class that implements ITypedList, to provide objects for databinding against
I'm trying to create a controller for a custom complex object but have some
I have a Generic List of objects that I've bound to a custom control.
I have a WCF web service that is accepting some custom objects and a
I have a list of custom objects that I use as the commandName object
We are binding a list of custom objects to an ASP.NET DropDownList in C#

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.