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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:49:53+00:00 2026-05-27T04:49:53+00:00

I have an issue with model binding a checkbox from a form to an

  • 0

I have an issue with model binding a checkbox from a form to an action on the server with a custom object containing a boolean.

Doing a google there seems to be a lot of problems with this, and no good solution. I have tried multiple things, and the problem seems to only happen when it is sent through an ajax call rather than a normal postback.

I have the following in my project (cut down for brevity):

View

@Html.LabelFor(model => model.TillAccess)
@Html.CheckBoxFor(m => m.TillAccess)

Model

public class CreateUserModel 
{
    public Boolean TillAccess { get; set; } 
}

Controller Action

[HttpPost]
public virtual ActionResult CreateUserWizard(CreateUserModel model)
{
   ...
}

I have added 2 buttons to the form, one sends as a postback and works. It sends the following with a postback if I check it on fiddler2:

TillAccess=true&TillAccess=false

It sends the following if I send it with the ajax button, and doesnt work:

{"TillAccess":["true","false"]}

Is there an issue with the way MVC model binds JSON that stops this working??

I can’t get this working through AJAX (which I will be using heavily), every other field binds fine, just not the checkbox, and the fact this works perfect as a normal postback suggests its an issue with the JSON serialiser or model binder for MVC?

UPDATE

The ajax call is as follows:

function CreateUser() {
        var FormData = JSON.stringify($('#CreateUserWizardForm').serializeObject());

        $.ajax({
            url: '@Url.Action(MVC.User.User.ActionNames.CreateUserWizard)',
            data: FormData,
            contentType: "application/json",
            dataType: "json",
            type: 'POST',
            cache: 'false',
            success: function (response) {
                alert('successfully created user!');
            },
            error: function (xhr) {
                alert('There was an error creating a user');
            }
        });
    }

Full ajax post is as follows just fyi:

{"BusinessUnitId":"cd56b710-0171-11e1-be50-0800200c9a66","Person.Salutation":"","Person.FirstName":"","Person.LastName":"","‌​TillAccess":["true","false"],"OfficeAccess":"false","TillLoginId":"","OfficeEmail‌​Address":"","OfficePassword":""}

UPDATE

The serializeObject method was downloaded from the internet (as I was having json issues with the post) and is as follows:

$.fn.serializeObject = function () {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name] !== undefined) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};

UPDATE

The reason I used this serializeObject method was due to an error I received if I used the inbuilt call of:

$('#CreateUserWizardForm').serialize()

It created a post of:

BusinessUnitId=cd56b710-0171-11e1-be50-0800200c9a66&Person.Salutation=&Person.FirstName=&Person.LastName=&TillAccess=true&TillAccess=false&OfficeAccess=false&TillLoginId=&OfficeEmailAddress=&OfficePassword=

Which gave me an error as follows:

System.ArgumentException: Invalid JSON primitive: BusinessUnitId.

UPDATE – ANSWER (I tried to add my answer at the bottom, but it won’t let me)

I found the solution. It was my AJAX call that was wrong. I changed it to the following and it is working.

$.ajax({
            url: '@Url.Action(MVC.User.User.ActionNames.CreateUserWizard)',
            data: $('#CreateUserWizardForm').serialize(),
            type: 'POST',
            cache: 'false',
            success: function (response) {
                alert('successfully created user!');
            },
            error: function (xhr) {
                alert('There was an error creating a user');
            }
        });

The old AJAX call:

var FormData = JSON.stringify($('#CreateUserWizardForm').serializeObject());

        $.ajax({
            url: '@Url.Action(MVC.User.User.ActionNames.CreateUserWizard)',
            data: FormData,
            contentType: "application/json",
            dataType: "json",
            type: 'POST',
            cache: 'false',
            success: function (response) {
                alert('successfully created user!');
            },
            error: function (xhr) {
                alert('There was an error creating a user');
            }
        });
  • 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-27T04:49:54+00:00Added an answer on May 27, 2026 at 4:49 am

    I found the solution. It was my AJAX call that was wrong. I changed it to the following and it is working.

    $.ajax({
                url: '@Url.Action(MVC.User.User.ActionNames.CreateUserWizard)',
                data: $('#CreateUserWizardForm').serialize(),
                type: 'POST',
                cache: 'false',
                success: function (response) {
                    alert('successfully created user!');
                },
                error: function (xhr) {
                    alert('There was an error creating a user');
                }
            });
    

    The old AJAX call:

    var FormData = JSON.stringify($('#CreateUserWizardForm').serializeObject());
    
            $.ajax({
                url: '@Url.Action(MVC.User.User.ActionNames.CreateUserWizard)',
                data: FormData,
                contentType: "application/json",
                dataType: "json",
                type: 'POST',
                cache: 'false',
                success: function (response) {
                    alert('successfully created user!');
                },
                error: function (xhr) {
                    alert('There was an error creating a user');
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an issue binding the AutoPupulating List in a form to update the
We have an issue using the PEAR libraries on Windows from PHP . Pear
I have an issue with using AWK to simply remove a field from a
This seems like the model binding is causing me issues. Essentially I have a
I have a view model sent to the edit action of my controller. The
I'm running into an issue trying to use @Html.DropDownListFor(). I have a model with
I have a strange issue in a datalist <asp:DataList ID=dl RepeatColumns=8 runat=server GridLines=None OnItemDataBound=dl_idb
I'm getting some trouble binding a date from QueryString : I have the following
I have a WCF service with net.tcp binding, hosted on the server as a
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So

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.