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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:03:02+00:00 2026-05-27T05:03:02+00:00

I have next JS code where I call controller method SaveSettings: function SaveSettings() {

  • 0

I have next JS code where I call controller method SaveSettings:

 function SaveSettings() {
        // get json object from knockoutjs object 
        var data = ko.toJSON(viewModel);
        var params = JSON.stringify(data);
        $.ajax({
            url: '/MyAjax/SaveSettings/',
            type: "POST",
            data: JSON.stringify(data),
            dataType: "JSON",
            contentType: "application/json; charset=UTF-8",
            success: function (result) {
                alert('ok');
            }
        });
    }

JSON Data have next format and sending to controller:

    {
"Name":"xcvxcvxcv",
"GeneralSetting":
{
    "Data1":{"IsSync":true,"Value":0},
    "Data2":{"IsSync":false,"Value":0},
    "PasswordLenght":{"IsSync":false,"Value":7},
    "PasswordMessage":{"IsSync":false,"Value":null},
    "DiscoverSerialPort":{"IsSync":false,"Value":true}
},
"MailSettings":
{
    "IsEnabled":{"IsSync":false,"Value":false},
    "ServerAddress":{"IsSync":false,"Value":null},
    "PortNumber":{"IsSync":false,"Value":0},
    "UserName":{"IsSync":false,"Value":null},
    "Password":{"IsSync":false,"Value":null},
    "IsSecureNetwork":{"IsSync":false,"Value":false},
    "PollFrequency":{"IsSync":false,"Value":0},
    "AdminFromEmail":{"IsSync":false,"Value":null},
    "AdminEmail":{"IsSync":false,"Value":null},
    "ReplyToEmail":{"IsSync":false,"Value":null},
    "BCCEmail":{"IsSync":false,"Value":null},
    "AuthenticationMethod":{"IsSync":false,"Value":0}
}
}

my controller method look like:

.....
     [HttpPost]
        public JsonResult SaveSettings(GlobalData data)
        {
            return Json(false.ToString(), JsonRequestBehavior.AllowGet);
        }

.....
public class GlobalData
{
    public string Name { get; set; }
    public GeneralSetting GeneralSetting { get; set; }
    public MailSetting MailSettings { get; set; }
}

public class MailSetting
{
    public SelectedProperty IsEnabled { get; set; }
    public SelectedProperty ServerAddress { get; set; }
    public SelectedProperty PortNumber { get; set; }
    public SelectedProperty UserName { get; set; }
    public SelectedProperty Password { get; set; }
    public SelectedProperty IsSecureNetwork { get; set; }
    public SelectedProperty PollFrequency { get; set; }
    public SelectedProperty AdminFromEmail { get; set; }
    public SelectedProperty AdminEmail { get; set; }
    public SelectedProperty ReplyToEmail { get; set; }
    public SelectedProperty BCCEmail { get; set; }
    public SelectedProperty AuthenticationMethod { get; set; }
}

public class GeneralSetting
{
    public SelectedProperty ScreenTimeout { get; set; }
    public SelectedProperty AdminScreenTimeout { get; set; }

    public SelectedProperty PasswordLenght { get; set; }
    public SelectedProperty PasswordMessage { get; set; }
    public SelectedProperty DiscoverSerialPort { get; set; }
}

public class SelectedProperty
{
    public bool IsSync { get; set; }
    public object Value { get; set; }
}

JSON object and my GlobalData class have the same structure.(look like they have)

But then method SaveSettings start working GlobalData variable contain NULL in all properties that define in GlobalData class.
Why this is happens ? Is my class structure incorrect for internal MVC mapping ?

  • 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-27T05:03:03+00:00Added an answer on May 27, 2026 at 5:03 am

    You are JSON serializing your view model twice: once with ko’s toJSON method and once with the native JSON.stringify method. One is sufficient:

    function SaveSettings() {
        var data = ko.toJSON(viewModel);
        $.ajax({
            url: '/MyAjax/SaveSettings/',
            type: 'POST',
            data: data,
            contentType: 'application/json; charset=UTF-8',
            success: function (result) {
                alert('ok');
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

myRs=myStmt.executeQuery(select i_col,col_name from tab_col) i=0 while (myRs.next()): list= myRs.getString(I_COL)+','+myRs.getString(COL_NAME) i have a jython code
I have the next function: function setImagesWidth(id,width) { var images = document.getElementById(id).getElementsByTagName(img); for(var i
I have the next query: var bPermisos = from b in ruc.Permisos where b.IdUsuario
I have the next code in javascript. I deleted some unnecessary items because it
I have the next code: Process p = Runtime.getRuntime().exec(args); and I want my program
I have the following code: if ($_POST['submit'] == Next) { foreach($_POST['info'] as $key =>
I have a fairly simple block of code. Sub Run(Name) on error resume next
I have the next code to work on ASP.Net controls. I'm trying to add
I am using the below method between the 50lines of JQuery Code. From the
Possible Duplicate: Why doesn't the CLR always call value type constructors Found next code

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.