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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:10:24+00:00 2026-05-27T09:10:24+00:00

I’m having a an odd problem with MVC3 and the model binding. When I

  • 0

I’m having a an odd problem with MVC3 and the model binding.
When I post a JSON object to my controller the model binder can’t create a typed object out of it at all. All the properties are the default (i.e. empty strings)

However if I create an instance on the server, and send it as a JSON action result the data on the wire looks identical.

I’ve tried with

$.ajaxSettings.traditional = true;

and it makes no difference

As an example if I post

{"RoutineName":"My new routine","Routines":[{"DayName":"Monday","Items":[21,31]}]}

The model binder fails, but coming from the server the data looks like

{"RoutineName":"Routine From Code","Routines":[{"DayName":"Monday","Items":[1,2]},{"DayName":"Tuesday","Items":[]}]}

The html used to generate this looks like

$('#submitRoutine').click(function () {
            var routines = [];
            $('.DayName').each(function (index, item) {
                var $item = $(item);
                var name = $item.html();
                var routineItems = [];
                $($item.attr('href')).find('.itemId').each(function () {
                    routineItems.push(parseInt($(this).val(), 10));
                });
                routines.push({
                    DayName: name,
                    Items: routineItems
                });
            });
            var routine = {
                RoutineName: $('#routineName').val(),
                Routines: routines
            };

            $.ajaxSettings.traditional = true;
            $.post('/Machine/CreateRoutine', JSON.stringify(routine),function (data) {},'json');
        });

So it looks like model binding from a typed object to JSON is ok, but coming back the other way isn’t. Is there something I’ve missed?

The models are in F#

type RoutineDayViewModel() =
    let mutable _name = String.Empty
    let mutable _items = new ResizeArray<int>()

    member x.DayName with get() = _name and set value = _name <- value
    member x.Items with get() = _items and set value = _items <- value

type RoutineViewModel() =
    let mutable _name = String.Empty
    let mutable _routines = new ResizeArray<RoutineDayViewModel>()

    member x.RoutineName with get() = _name and set value = _name <- value
    member x.Routines with get() = _routines and set value = _routines <- value

EDIT:
I’ve also tried with the following C# classes and get the same result

 public class RoutineDayViewModel
    {
        public string DayName { get; set; }
        public List<int> Items{ get; set; }
    }

    public class RoutineViewModel
    {
        public string RoutineName { get; set; }
        public List<RoutineDayViewModel> Routines { get; set; }
    }

I’ve also added the following to the global.asax

ValueProviderFactories.Factories.Add(new JsonValueProviderFactory())

Thanks

  • 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-27T09:10:25+00:00Added an answer on May 27, 2026 at 9:10 am

    You need to set the request content type to application/json if you intend to send a JSON formatted request which is what you are doing with the JSON.stringify method. So instead of:

    $.post('/Machine/CreateRoutine', JSON.stringify(routine),function (data) {},'json');
    

    you could use:

    $.ajax({
        url: '/Machine/CreateRoutine',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify(routine),
        success: function (data) {
    
        } 
    });
    

    With this you don’t need to set $.ajaxSettings.traditional nor you should be adding any JsonValueProviderFactory in your Global.asax as this provider is already added by default in ASP.NET MVC 3.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to create an if statement in PHP that prevents a single post
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string

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.