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

The Archive Base Latest Questions

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

I have a custom model binder that takes a comma separated list and cleans

  • 0

I have a custom model binder that takes a comma separated list and cleans out any empty values, then passes it along to the default model binder. This worked in ASP.NET MVC Preview 2, but when I upgraded to RC2, the below won’t compile because the interface of ValueProvider only has a GetValue() method, no [] accessor. Is what I’m doing below possible through some other mechanism in the binding context? I’d rather not have to create a full blown model binder for such a simple situation. The main goal is when the values are bound to a List<SomeEnum>, any empty values are skipped.

public class EnumListModelBinder : IModelBinder
{
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        var result = bindingContext.ValueProvider[bindingContext.ModelName];
        string[] rawValues = (string[])result.RawValue;
        var newValues = new List<string>();
        foreach (string value in rawValues)
        {
            if (!String.IsNullOrEmpty(value))
            {
                newValues.Add(value);
            }
        }

        string newValuesAttempted = String.Join(",", newValues.ToArray());
        // overwrite the ValueProviderResult with the cleaned up csv list
        // this is the part I'm not sure how to implement using the interface
        bindingContext.ValueProvider[bindingContext.ModelName] = 
           new ValueProviderResult(newValues.ToArray(), newValuesAttempted, result.Culture);

        return System.Web.Mvc.ModelBinders.Binders.DefaultBinder.BindModel(controllerContext, bindingContext);
    }
}
  • 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:22:21+00:00Added an answer on May 13, 2026 at 8:22 pm

    There wasn’t much of a solution here now that the ValueProvider collection is readonly. Instead I ended up using a custom model binder

    Is there a way to have the DefaultModelBinder ignore empty items when binding to a List<Enum>

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

Sidebar

Related Questions

In my application I have a custom model binder that I set to the
I have a Model that contains a List of a custom type. I want
So I have one custom model binder that inherits from DefaultModelBinder, where I am
I have a custom model binder with public override object BindModel(controllerContext, bindingContext) that checks
I have created a custom Model Binder that inherits from DefaultModelBinder, and overriding the
I'm using the MVC 2 RC. I have a custom model binder that used
I have written a custom model binder for List in my MVC project however
I have a custom model binder which pulls an implementation of an interface from
This is my custom model binder. I have my breakpoint set at BindModel but
I have a model class that uses a custom validator as shown in following

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.