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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:00:47+00:00 2026-06-02T08:00:47+00:00

I am trying to send some serialized data to the view and bind it

  • 0

I am trying to send some serialized data to the view and bind it to the knockout code. I am using json.net library for serialization because I want to pass the constants of an enum to the view ( and not the underlying integers.) I am not sure how my controller returning Json data should look like. Here is the sample code:

My view model that will be serialized:

public class FranchiseInfoViewModel
    {

        public string FolderName { get; set; }

        [JsonConverter(typeof(StringEnumConverter))]
        public LobbyTemplateOptions LobbyTemplate { get; set; }

        public List<LobbyTemplateOptions> LobbyTemplates { get; set; }

        public void Initialize()
        {
            FolderName = "Test";

            LobbyTemplate = LobbyTemplateOptions.G;
            LobbyTemplates = new List<LobbyTemplateOptions>
                                 {
                                     LobbyTemplateOptions.G,
                                     LobbyTemplateOptions.H,
                                     LobbyTemplateOptions.I
                                 };

Enum:

[JsonConverter(typeof(StringEnumConverter))]
    public enum LobbyTemplateOptions
    {
        G = 7,
        H = 8,
        I = 9
    }

My knockout code:

$(function () {
    omega.FranchiseInfo = (function () {
        var FolderName = ko.observable();
        var LobbyTemplates = ko.observableArray([]);

        $.getJSON("FranchiseData", function (data) {
            FolderName(data.FolderName);

            for (var i = 0; i < data.LobbyTemplate.length; i++) {
               LobbyTemplates.push(data.LobbyTemplate[i]);
            }
        });

        return {
            folderName: FolderName,

            lobbyTemplates: LobbyTemplates
        }
    } ());
    ko.applyBindings(omega.FranchiseInfo);
})

        }

I am wondering how my controller that passes serialized Json data to the view should look like as I have not used json.net and I am relatively new to programming:

Controller passing the Json data to the view:

 public JsonResult FranchiseData()
            {
                FranchiseInfoViewModel franchiseInfoViewModel = new FranchiseInfoViewModel();
                franchiseInfoViewModel.MapFranchiseInfoToFranchiseInfoViewModel();
                string json = JsonConvert.SerializeObject(franchiseInfoViewModel);

                // this is how I do it with the default Json serializer
               // return Json(franchiseInfoViewModel, JsonRequestBehavior.AllowGet);
            }

I would be very gratefull if somebody can post a working example of my controller. Thank You!

  • 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-02T08:00:49+00:00Added an answer on June 2, 2026 at 8:00 am

    You need to implement JsonNetResult.

    public class JsonNetResult : ActionResult
    {
      public Encoding ContentEncoding { get; set; }
      public string ContentType { get; set; }
      public object Data { get; set; }
    
      public JsonSerializerSettings SerializerSettings { get; set; }
      public Formatting Formatting { get; set; }
    
      public JsonNetResult()
      {
        SerializerSettings = new JsonSerializerSettings();
      }
    
      public override void ExecuteResult(ControllerContext context)
      {
        if (context == null)
          throw new ArgumentNullException("context");
    
        HttpResponseBase response = context.HttpContext.Response;
    
        response.ContentType = !string.IsNullOrEmpty(ContentType)
          ? ContentType
          : "application/json";
    
        if (ContentEncoding != null)
          response.ContentEncoding = ContentEncoding;
    
        if (Data != null)
        {
          JsonTextWriter writer = new JsonTextWriter(response.Output) { Formatting = Formatting };
    
          JsonSerializer serializer = JsonSerializer.Create(SerializerSettings);
          serializer.Serialize(writer, Data);
    
          writer.Flush();
        }
      }
    }
    

    To use it, in your case you need to rewrite controller method in this way:

    public ActionResult FranchiseData()
    {
        FranchiseInfoViewModel franchiseInfoViewModel = new FranchiseInfoViewModel();
        franchiseInfoViewModel.MapFranchiseInfoToFranchiseInfoViewModel();
    
        JsonNetResult jsonNetResult = new JsonNetResult();
        jsonNetResult.Formatting = Formatting.Indented;
        jsonNetResult.Data = franchiseInfoViewModel;
    
        return jsonNetResult;
    }
    

    (implementation of JsonNetResult above was taken this blog post
    http://james.newtonking.com/archive/2008/10/16/asp-net-mvc-and-json-net.aspx )

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

Sidebar

Related Questions

I'm trying to send some small data over UDP using the AsyncUdpSocket library .
I am trying to send some data using NSNotification but get stuck. Here is
I am currently trying to send some data from and Android application to a
I'm trying to send email with some images attached in django. Code used is
I'm trying to send a URL with some parameters using HttpPost but it has
I'm trying to send some data from the server to the client, but the
I am trying to send some data from a LINQ query in C# to
I'm trying to send some data via JQuery ajax to a grails controller Here's
I'm trying to send some data from a C++ server to a C# client.
I'm trying to send some data to a PHP script online to submit online

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.