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

The Archive Base Latest Questions

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

I am trying to find some examples of building a custom model binder for

  • 0

I am trying to find some examples of building a custom model binder for a unique binding scenario I need to handle, but all of the articles I found were for older versions of MVC which are no longer relevant in MVC2. I’ve been referencing the DefaultModelBinder source code to try to get a general feel for what I need to do, but it’s entirely more complicated than my scenario and I’m having trouble isolating the specific logic I need to implement.

My goal is to take a collection of Checkbox/Textbox pairs and for all of the Checked pairs I would like to create a key/value pair of the Checkbox’s value and the associated Textbox’s value. After aggregating this data I need to do some string serialization on the collection so I can store it in a string property of the desired Model type. I already the data being sent from the form in a manageable format which will allow me to relate a given Checkbox to a specific Textbox, it’s just a matter of figuring out how to get all the pieces where I need them.

Does anyone know of some up-to-date tutorials that can get me started with building a custom model binder?

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

    I don’t know why you think a lot has changed since MVC 1 regarding custom model binders. But If I understand what you are trying to do, it should be fairly easy.

    public class CustomModelBinder : DefaultModelBinder {
        public override object BindModel(ControllerContext controllerContext, 
            ModelBindingContext bindingContext) {
    
            NameValueCollection form = controllerContext.HttpContext.Request.Form;
            //get what you need from the form collection
    
            //creata your model
            SomeModel myModel = new SomeMode();
            myModel.Property = "value";
            //or add some model errors if you need to
            ModelStateDictionary mState = bindingContext.ModelState;
            mState.Add("Property", new ModelState { });
            mState.AddModelError("Property", "There's an error.");
    
            return myModel; //return your model
        }
    }
    

    And your action :

    public ActionResult Contact([ModelBinder(typeof(CustomModelBinder))]SomeModel m){
        //...
    }
    

    Was that the kind of information you are looking for?

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

Sidebar

Related Questions

I am trying to find some examples but no luck. Does anyone know of
I've been trying for some time to find some examples or explenations of java
I've been trying to find some manual information on this, but my search is
I am trying to find some code examples which allow me to hook up
I was trying to find some examples on how to find a given set's
I'm trying to find some sample code or examples or good documentation on how
Trying to find some examples on the intertubes. I am thinking of state or
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Am trying to find some text only if it contains english letters and numbers
I have been trying to find some resource on this topic for a while

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.