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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:17:48+00:00 2026-06-13T05:17:48+00:00

Every so often at Rentler we see the error System.FormatException , String was not

  • 0

Every so often at Rentler we see the error

System.FormatException, String was not recognized as a valid Boolean

in our health monitoring. As it turns out, it looks like our customers are occasionally truncating the end of the url when copy/pasting it elsewhere. It just so happens that a boolean parameter tends to be on the end of the string, and when a customer shares it over some social network we get dumped with error reports.

https://{domain}/search?sid=17403777&nid=651&location=840065&propertytypecode=1&photosonly=fals

We use model binding for everything, so I’m not really sure how to deal with this. I could change the property to a string and attempt to parse it in the controller action, but that’s sloppy. Is there any simple, fluent way to get the model binder to TryParse() it and just resolve to false if it can’t?

  • 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-06-13T05:17:49+00:00Added an answer on June 13, 2026 at 5:17 am

    how about custom model binder for boolean data type? you would need something like this:

    /// <summary>
    /// A custom model binder for boolean values. This behaves the same as the default
    /// one, except it will resolve the value to false if it cannot be parsed.
    /// </summary>
    public class BooleanModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            ValueProviderResult valueResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
    
            //MVC checkboxes need specific handling in checked state
            if (string.Equals(valueResult.AttemptedValue, "true,false"))
            {
                AddToModelState(bindingContext, valueResult);
                return true;
            }
    
            bool parsed = false;
            if (Boolean.TryParse(valueResult.AttemptedValue, out parsed))
            {
                AddToModelState(bindingContext, valueResult);
                return parsed;
            }
    
            return false;
        }
    
        private static void AddToModelState(ModelBindingContext bindingContext, ValueProviderResult valueResult)
        {
            bindingContext.ModelState.Add(bindingContext.ModelName, new ModelState { Value = valueResult });
        }
    }
    
    //in Global.asax
    protected void Application_Start()
    {
        ...
        ModelBinders.Binders.Add(typeof(bool), new BooleanModelBinder());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Every so often I see Speed Up Your PC programs that offer a RAM
Every now and then (ahem...) my code crashes on some system; quite often, my
I have a problem I see every so often - I create a CSS
Every so often on here I see someone's code and what looks to be
In our prod server, every so often the requests to an external service start
I see questions on SO every so often about overloading the comma operator in
Every so often I have to remove a user from our database. Users are
When using MonkeyRunner, every so often I get an error like: 120830 18:39:32.755:S [MainThread]
This is a problem I come across every so often; I always end up
Every so often, things work in my local PHP development environment, while in my

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.