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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:37:23+00:00 2026-06-11T16:37:23+00:00

I have the following class on my server: public class JsonDialog { public IEnumerable<string>

  • 0

I have the following class on my server:

public class JsonDialog
{
    public IEnumerable<string> Errors { set; get; }
    public string Modified { set; get; }
    public string ModifiedBy { get; set; }
    public string PartitionKey { set; get; }
    public string PartitionKeyNew { set; get; }
    public string RowKey { get; set; }
    public string RowKeyNew { get; set; }
    public bool Success { set; get; }
}

In my MVC action method I return a JsonResult:

                return Json(new JsonDialog
                {
                    Success = false,
                    Errors = errors
                });

In my client code I have the following:

    $.ajax({
        url: href,
        dataType: 'json',
        type: 'POST',
        data: $form.serializeArray()
        })
        .done(onDone)
        .fail(onFail);


var onDone = function (json, textStatus, XMLHttpRequest) {
    json = json || {};
    if (json.Success) {

Because I am using a class on the server the compiler checks to ensure I don’t make any spelling mistakes and for example it will not allow me to enter “success = false”. However on the client there’s no checking and I could code json.sUccEss and it would still be okay with that but it would not give me the desired result.

Is there any way in Javascript that I can have some error checking like I have on the server? Anything like getting data into a class and having the IDE check that class fields are correct?

  • 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-11T16:37:24+00:00Added an answer on June 11, 2026 at 4:37 pm

    I solve this (partially) by creating a matching object in JS with, what I refer to as a ‘factory’ method (but that’s a misnomer if you’re using the term ‘factory’ as is referred to here. It’s really more analogous to ‘casting’, but since JS doesn’t have strong typing, that’s not exactly right either.

    Obviously, this code pattern is also pretty verbose if all you’re doing is trying to get intellisense working, but if you have methods on your JS-side object… we’ll fictionally say: JsonResult.prototype.markErrorsReviewed…then this pattern where you get an instance of a given ‘class’ is helpful.

    For the sake of brevity, I’m going to just use your C# class on which to base my JS:

    var JsonResult = function () {
        this.Errors = [];
        this.Modified = null;
        this.ModifiedBy = null;
        //...rest of your properties, defaulted as necessary
    }
    
    JsonResult.factory = function (o) {
        var j = new JsonResult();
        $.extend(j, o);
        //do other processing here if needed (for example, ASP.NET serializes DateTime retardedly)
        return j;
    }
    

    AJAX:

    $.ajax({
        success: function(json, status, xhr) {
            var myobj = JsonResult.factory(json);
            //VS2010 will now give you intellisense w/ proper property names on myobj
            //Note: it's still buggy and sometimes won't detect things properly, but it usually works
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following class public class Account { IEnumerable<AccountData> Data { get; set;
On server I have the following class public class A { string a1 {get;
I have the following class public class MenuVeiculo { public string Nome { get;
I have following ViewModel: public class Bulletin1ViewModel { [Required] public String NumberDelegations { get;
In server side I have following class public class EditorContext { public Module Module
I have following design requirements: interface Server {} public class ServerImpl implements Server {}
I have the following class: public class Email { public System.Net.Mail.SmtpClient SmtpClient { get
I have the following set: public class Account : AuditableTable, IAccount { } public
If i have the following entity: public class PocoWithDates { public string PocoName {
I have the following class: public class getURLData extends AsyncTask<String, Integer, String>{ @Override protected

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.