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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:04:36+00:00 2026-05-13T22:04:36+00:00

I need to implement a functionality to allow users to enter price in any

  • 0

I need to implement a functionality to allow users to enter price in any form, i.e. to allow 10 USD, 10$, $10,… as input.

I would like to solve this by implementing a custom model binder for Price class.

 class Price { decimal Value; int ID; } 

The form contains an array or Prices as keys

keys:
"Prices[0].Value"
"Prices[0].ID"
"Prices[1].Value"
"Prices[1].ID"
...

The ViewModel contains a Prices property:

public List<Price> Prices { get; set; }

The default model binder works nicely as long as the user enters a decimal-convertible string into the Value input.
I would like to allow inputs like “100 USD”.

My ModelBinder for Price type so far:

public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
    Price res = new Price();
    var form = controllerContext.HttpContext.Request.Form;
    string valueInput = ["Prices[0].Value"]; //how to determine which index I am processing?
    res.Value = ParseInput(valueInput) 

    return res;
}

How do I implement a custom model Binder that handles the arrays correctly?

  • 1 1 Answer
  • 1 View
  • 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-13T22:04:37+00:00Added an answer on May 13, 2026 at 10:04 pm

    Got it: The point is to not try to bind a single Price instance, but rather implement a ModelBinder for List<Price> type:

        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            List<Price> res = new List<Price>();
            var form = controllerContext.HttpContext.Request.Form;
            int i = 0;
            while (!string.IsNullOrEmpty(form["Prices[" + i + "].PricingTypeID"]))
            {
                var p = new Price();
                p.Value = Process(form["Prices[" + i + "].Value"]);
                p.PricingTypeID = int.Parse(form["Prices[" + i + "].PricingTypeID"]);
                res.Add(p);
                i++;
            }
    
            return res;
        }
    
    //register for List<Price>
    ModelBinders.Binders[typeof(List<Price>)] = new PriceModelBinder();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 463k
  • Answers 463k
  • 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 I think you're confusing autoboxing with type inference. Type inference… May 16, 2026 at 12:42 am
  • Editorial Team
    Editorial Team added an answer You are not creating a new function on each iteration… May 16, 2026 at 12:42 am
  • Editorial Team
    Editorial Team added an answer No, #foo input should find all input descendants of #foo.… May 16, 2026 at 12:42 am

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.