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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:26:58+00:00 2026-06-17T08:26:58+00:00

I’ve got a model for my Page Creation: public class PageCreateModel : ActionModel {

  • 0

I’ve got a model for my Page Creation:

public class PageCreateModel : ActionModel
{
    public IList<KeyValuePair<Guid, string>> AvailablePermissions { get; set; }
    public IList<KeyValuePair<Guid, string>> AvailableUsers { get; set; }
    public IList<KeyValuePair<Guid, string>> AvailableGroups { get; set; }

    public string Heading { get; set; }
    public bool ShowHeading { get; set; }
    public string Description { get; set; }
    public ICollection<string> RouteUrls { get; set; }
    public IList<KeyValuePair<Guid, string>> SelectedEditingPermissions { get; set; }
    public IList<KeyValuePair<Guid, string>> SelectedEditingUsers { get; set; }
    public IList<KeyValuePair<Guid, string>> SelectedEditingGroups { get; set; }
}

And I am using knockout mapping to convert this into a knockout model on page load:

 var mappedModel = ko.mapping.fromJS(@Html.Raw(JsonConvert.SerializeObject(Model)));

Upon posting and using this code:

mappedModel.save = function(form) {
        mappedModel.AvailablePermissions([]);
        mappedModel.AvailableUsers([]);
        mappedModel.AvailableGroups([]);
        console.log(ko.toJS(mappedModel));
        ko.utils.postJson('@Url.Action("Create", "Page")', { pageCreateModel: ko.toJS(mappedModel) });
    };

It goes to this Action:

    [HttpPost]
    public ActionResult Create(PageCreateModel pageCreateModel)
    {

        return View(HydrateModel(pageCreateModel));
    }

At this point my standard property values get posted find. But my collections (so far on my page I’ve only added SelectedEditingUsers) have empty objects in the collection. For instance if on the page I add 2 users to the collection, and I post it. The MVC model’s SelectedEditingUsers will have a collection of two, but those objects contain an Empty Guid and null for the value.

Here is the data being sent to the server from Chrome console:

pageCreateModel:{“AvailablePermissions”:[],”AvailableUsers”:[],”AvailableGroups”:[],”Heading”:”Test”,”ShowHeading”:true,”Description”:null,”RouteUrls”:null,”SelectedEditingPermissions”:[],”SelectedEditingUsers”:[{“Key”:”d81f409a-5fed-4330-8640-004bede4e6fb”,”Value”:”User1″},{“Key”:”5628ad64-567b-499d-bee1-cb6c3dc397eb”,”Value”:”User2″}],”SelectedEditingGroups”:[],”ActionSuccess”:false,”ActionMessage”:null,”ko_mapping“:{“ignore”:[],”include”:[“_destroy”],”copy”:[],”observe”:[],”mappedProperties”:{“AvailablePermissions[0].Key”:true,”AvailablePermissions[0].Value”:true,”AvailablePermissions1.Key”:true,”AvailablePermissions1.Value”:true,”AvailablePermissions[2].Key”:true,”AvailablePermissions[2].Value”:true,”AvailablePermissions[3].Key”:true,”AvailablePermissions[3].Value”:true,”AvailablePermissions[4]…[etc]

How can I fix it so that the full model gets properly received by MVC? I need to use postJSON so I can use RedirectToAction and other similar things.

EDIT: Trying the AJAX call instead:

 mappedModel.save = function(form) {
        mappedModel.AvailablePermissions([]);
        mappedModel.AvailableUsers([]);
        mappedModel.AvailableGroups([]);
        //mappedModel.__ko_mapping__([]);
        //console.log(ko.toJS(mappedModel));
        $.ajax({
            url: '@Url.Action("Create", "Page")',
            type: 'POST',
            data: ko.toJSON(mappedModel),
            contentType: 'application/json; charset=utf-8',
            success: function(data) {
                alert("Success!");
            }
        });
        //ko.utils.postJson('@Url.Action("Create", "Page")', { pageCreateModel: ko.toJS(mappedModel) });
        //ko.utils.postJson($("form")[0], { pageCreateModel: ko.toJS(mappedModel) });
        //ko.utils.postJson('@Url.Action("Test", "Page")', { ko.toJS(mappedModel) });

    };

And I still get the same problem:

enter image description here

And here is the POST from that:

{“AvailablePermissions”:[],”AvailableUsers”:[],”AvailableGroups”:[],”Heading”:”Test”,”ShowHeading”:true,”Description”:null,”RouteUrls”:null,”SelectedEditingPermissions”:[],”SelectedEditingUsers”:[{“Key”:”5628ad64-567b-499d-bee1-cb6c3dc397eb”,”Value”:”User1″},{“Key”:”6d7439aa-7728-4add-953f-28b306fff5d0″,”Value”:”User2″}],”SelectedEditingGroups”:[],”SelectedViewingPermissions”:[],”SelectedViewingUsers”:[],”SelectedViewingGroups”:[],”ActionSuccess”:false,”ActionMessage”:null,”ko_mapping“:{“ignore”:[],”include”:[“_destroy”],”copy”:[],”observe”:[],”mappedProperties”:{“AvailablePermissions[0].Key”:true,”AvailablePermissions[0].Value”:true,”AvailablePermissions1.Key”:true,”AvailablePermissions1.Value”:true,”AvailablePermissions[2].Key”:true,”AvailablePermissions[2].Value”:true,”AvailablePermissions[3].Key”:true,…etc”

  • 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-17T08:26:58+00:00Added an answer on June 17, 2026 at 8:26 am

    ko.utils.postJson doesn’t set the Content-Type request header to application/json. It will simply send the request as form encoded value. So use $.ajax instead which allows you to specify the correct content type header:

    mappedModel.save = function(form) {
        mappedModel.AvailablePermissions([]);
        mappedModel.AvailableUsers([]);
        mappedModel.AvailableGroups([]);
        $.ajax({
            url: '@Url.Action("Create", "Page")',
            type: 'POST',
            data: ko.toJSON(mappedModel),
            contentType: 'application/json; charset=utf-8',
            success: function(data) {
               ...do something
            }
        });
    };
    

    The Content-Type request header is used by ASP.NET MVC when trying to read the request in order to know how is this request being serialized.

    In addition to that you might want to replace the IList<KeyValuePair<Guid, string>> types with IList<MyViewModel> where MyViewModel would be a view model class exposing two public properties: Key and Value. I am not sure that the JSON serializer would cope well with those KeyValuePair<Guid, string> type.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
i got an object with contents of html markup in it, for example: string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
Specifically, suppose I start with the string string =hello \'i am \' me And

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.