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

The Archive Base Latest Questions

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

I would like to do complex validation on my form that contains a list

  • 0

I would like to do complex validation on my form that contains a list of objects.

My form contains a list of, let’s say, MyObjects. MyObject consists of a double amount and a MyDate which is just a wrapper around DateTime.

public class MyObject
{
    public MyDate Date { get; set; } //MyDate is wrapper around DateTime
    public double Price { get; set; }
}

The form…

<input type="text" name="myList[0].Date" value="05/11/2009" />
<input type="text" name="myList[0].Price" value="100,000,000" />

<input type="text" name="myList[1].Date" value="05/11/2009" />
<input type="text" name="myList[1].Price" value="2.23" />

Here is my Action

public ActionResult Index(IList<MyObject> myList)
{
   //stuff
}

I want to allow the user to enter in 100,000,000 for a Price and for the custom model binder to strip the ‘,’ so it can convert to a double. Likewise, I need to convert the 05/11/2009 to a MyDate object. I thought about creating a MyObjectModelBinder but dont know what to do from there.

ModelBinders.Binders[typeof(MyObject)] = new MyObjectModelBinder();

Any help appreciated.

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

    Here’s a sample implementation of a custom model binder:

    public class MyObjectModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            // call the base method and let it bind whatever properties it can
            var myObject = (MyObject)base.BindModel(controllerContext, bindingContext);
            var prefix = bindingContext.ModelName;
            if (bindingContext.ValueProvider.ContainsKey(prefix + ".Price"))
            {
                string priceStr = bindingContext.ValueProvider[prefix + ".Price"].AttemptedValue;
                // priceStr = 100,000,000 or whatever the user entered
                // TODO: Perform transformations on priceStr so that parsing works
                // Note: Be carefull with cultures
                double price;
                if (double.TryParse(priceStr, out price))
                {
                    myObject.Price = price;
                }
            }
    
            if (bindingContext.ValueProvider.ContainsKey(prefix + ".Date"))
            {
                string dateStr = bindingContext.ValueProvider[prefix + ".Date"].AttemptedValue;
                myObject.Date = new MyDate();
                // TODO: Perform transformations on dateStr and set the values 
                // of myObject.Date properties
            }
    
            return myObject;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 211k
  • Answers 211k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, your regexp wouldn't help with SQL injection much at… May 12, 2026 at 10:06 pm
  • Editorial Team
    Editorial Team added an answer Your Button (i.e. it's databinding) needs to be notified that… May 12, 2026 at 10:06 pm
  • Editorial Team
    Editorial Team added an answer Backwards compatibility. Earlier versions of Spring only had getModel(), newer… May 12, 2026 at 10:06 pm

Related Questions

I’ve been trying to wrap my head around how to expose my domain objects
I have an element that can have multiple types (not my design). The element
I recently discovered metaclasses in python. Basically a metaclass in python is a class
I'm going through the railscast no 73 ( http://railscasts.com/episodes/73-complex-forms-part-1 ), where Ryan Bates explains

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.