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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:24:12+00:00 2026-06-05T14:24:12+00:00

Given the following client side code fragment: var vm = { Input : Label:

  • 0

Given the following client side code fragment:

var vm = {
  Input : "Label: Value",
  Rules : [
    { Name : "RemoveString",
      Params : [
        "Label: "
      ]
    }
  ]
};

$.post("/API/ApplyRule", vm, function(data) { });

And the following ViewModel on server side:

[Serializable]
public class ApplyRuleRequestViewModel
{
    public string Input { get; set; }
    public List<RuleViewModel> Rules { get; set; }
}

[Serializable]
public class RuleViewModel
{
    public string Name { get; set; }
    public List<string> Params { get; set; }
}

And the following controller code:

public class APIController : Controller
{
    [HttpPost]
    public ActionResult ApplyRule(ApplyRuleRequestViewModel model)
    {
        //Problem here... model is not fully deserialized into the ViewModel object.
        return View();
    }
}

I am having a problem trying to serialize the Rules portion of the client side ViewModel. When debugging the code at the controller line above that said //Problem…, I see that the top level object properties made it, but not the sub-object. So, I get something like:

var vm = new ApplyRuleRequestViewModel {
  Input = "Label: Value",
  Rules = new List<RuleViewModel> {
     new RuleViewModel { Name = null, Parameters = null }
  }
}

I am expecting something like:

var vm = new ApplyRuleRequestViewModel {
  Input = "Label: Value",
  Rules = new List<RuleViewModel> {
     new RuleViewModel { 
         Name = "RemoveString", 
         Parameters = new List<string> { "Label: " }
     }
  }
}

What am I doing wrong here?
Why is it not binding the Rules array properly?

Do you need to create your own custom model binder to bind this properly? If so, how?

  • 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-05T14:24:13+00:00Added an answer on June 5, 2026 at 2:24 pm

    You can send your message as JSON.

    var vm = {
      Input : "Label: Value",
      Rules : [
        { Name : "RemoveString",
          Params : [
            "Label: "
          ]
        }
      ]
    };
    
    $.postJson("/API/ApplyRule", vm, function(data) { }); // See below for definition of `.postJson`.
    

    The last argument json will set the accepts header to indicate JSON is wanted. The default model binder should automatically interact with the built-in JsonValueProviderFactory to properly read the structured message.

    EDIT Missed something. You need to set the contentType, so .post as it stands may not work.

    Here’s a helper method for posting JSON (not just POSTING and receiving json, as post would do).

    $.postJson = function(url, data, success) {
      $.ajax({
                url: url,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(data),
                contentType: 'application/json; charset=utf-8',
                success: success
            }); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following C# code: var product = new List<int>(); for (int n1 =
Given the following C# code: public object CallJavaScriptFunction(string functionName, params object[] args) { object
Given following array: var arr = [undefined, undefined, 2, 5, undefined, undefined]; I'd like
Given the following code, is there a way I can call class A's version
I'm getting the error when attempting to add to a client-side EntitySet. The following
I'm using the following code to watch for changes to a given SELECT element.
I want the following functions and I know about the client side domain restriction
I'm following the instructions given on FB Developer, but I just can't get client
In my application following is the scenario, client request for eventId. In server side,open
// given following array: $data = array( 0=>array( data=>object1, col=>array( 0=>array( data=>object2, col=>array( 0=>array(

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.