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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:52:33+00:00 2026-05-23T02:52:33+00:00

So, I have a search form in my website which posts Search.Value as a

  • 0

So, I have a search form in my website which posts Search.Value as a parameter where in the project there is a class called Search with a property Value which is an object. When the value is bound by the model binder, object is always System.String[] regardless if I pass in a single number, a single word or anything else.

Can someone explain to me why that is, or if I can make it stop doing that?

Here’s the code:

// Search.cs
public sealed class Search {
    private object _Value = null;

    public object Value {
        get {
            return this._Value;
        }
        set {
            if (value != null) {
                this._Value = value;

                this.IsInt32 = (this._Value is Int32);
                this.IsString = (this._Value is String);
            };
        }
    }

    public bool IsInt32 { get; set; }
    public bool IsString { get; set; }
}

// SearchController.cs
[HttpPost]
public ActionResult List(
    [Bind(Prefix = "Search", Include = "Value")] Search Search) {
    return this.View();
}

// Form HTML
<form action="/Administration/Search" method="post">
    @Html.TextBox("Search.Value", Model.Search.Value, new { type = "search", placeholder = "Search", size = 48, required = string.Empty })
    <input type="submit" value="&#8981;" />
</form>

UPDATE

Per @Darin’s suggestion and example I’ve made a custom binder and it seems to be working so far. Here’s the code if anyone else runs into this, modify as needed of course:

public class SearchModelBinder : DefaultModelBinder {
    public override object BindModel(
        ControllerContext ControllerContext,
        ModelBindingContext BindingContext) {
        if (BindingContext == null) {
            throw new ArgumentNullException("BindingContext");
        };

        ValueProviderResult ValueResult = BindingContext.ValueProvider.GetValue(BindingContext.ModelName + ".Value");

        if (ValueResult == null) {
            return (null);
        };

        string Value = ValueResult.AttemptedValue;

        if (String.IsNullOrEmpty(Value)) {
            return (null);
        };

        int Int;

        if (int.TryParse(Value, out Int)) {
            return new Search {
                Value = Convert.ToInt32(Value)
            };
        };

        long Long;

        if (long.TryParse(Value, out Long)) {
            return new Search {
                Value = Convert.ToInt64(Value)
            };
        };

        return new Search {
            Value = Value
        };
    }
}
  • 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-23T02:52:34+00:00Added an answer on May 23, 2026 at 2:52 am

    No idea what you are trying to achieve, why are you using object, … but you could write a custom model binder for this Search model. This model binder will assign directly the parameter that is sent in the request to the Value property:

    public class SearchModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName + ".Value");
            if (value != null)
            {
                return new Search
                {
                    Value = value.AttemptedValue
                };
            }
            return base.BindModel(controllerContext, bindingContext);
        }
    }
    

    which you could register in Global.asax:

    ModelBinders.Binders.Add(typeof(Search), new SearchModelBinder());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a search form with a query builder. The builder is activated by
I have a search form in an app I'm currently developing, and I would
I have a search form on each of my pages. If I use form
I have a search form and result list. The form allows the user to
I have a really simple search form with the following Label (Search) Textbox (fixed
I've got search form, which contains checkboxlist which is binded to my model. So
I have search in MSDN and I can't figure where are the POST parameters
I have a search box that doesn't have a submit button, I need to
I have a search program that will be looking at a database from a
I have a search query that I'm inheriting and attempting to optimize. I am

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.