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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:48:44+00:00 2026-06-10T12:48:44+00:00

I have returning a Json(myObj) action result. The myObj is of type Badge The

  • 0

I have returning a Json(myObj) action result. The myObj is of type Badge

The only two objects that Badge has that could cause a loop from a serializer, are:

public class Badge
{
    public Badge() { }

    public Badge(String Name, String Description)
    {
        this.Name = Name;
        this.Description = Description;
    }

    [ScriptIgnore]
    public virtual BadgeType BadgeType { get; set; }
    [ScriptIgnore]
    public virtual ICollection<User> Users { get; set; }

    public int ID { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string PrerequisiteCriteriaRef { get; set; }

    //PrerequisiteID

    public static Badge CreateForSeeder(BaseDBContext db, String Name, String Description, int TypeID)
    {
        Badge b = new Badge();
        b.Name = Name;
        b.Description = Description;
        b.BadgeType = db.BadgeTypes.Where(x => x.TypeID == TypeID).FirstOrDefault();
        return b;
    }
}

Which I’ve given the attribute, but it’s not helping out at all…?

  • 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-10T12:48:45+00:00Added an answer on June 10, 2026 at 12:48 pm

    The JavaScriptSerializer (which is what is used when you return Json) definitely honors the [ScriptIgnore] attribute.

    Here’s a proof:

    Model:

    public class User
    {
        public Badge Badge { get; set; }
    }
    
    public class Badge
    {
        [ScriptIgnore]
        public virtual ICollection<User> Users { get; set; }
    
        public int ID { get; set; }
        public string Name { get; set; }
    }
    

    Controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var badge = new Badge
            {
                ID = 1,
                Name = "badge"
            };
            var user = new User
            {
                Badge = badge
            };
            badge.Users = new[] { user }.ToList(); 
    
            return Json(badge, JsonRequestBehavior.AllowGet);
        }
    }
    

    If you remove the [ScriptIgnore] attribute from the Users property you will get a circular reference error.

    So I guess that your problem is somewhere else.

    But personally I would recommend you using view models instead of those [ScriptIgnore] attributes.

    So you simply define a view model that will contain only the properties you need for the given view:

    public class BadgeViewModel
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
    

    and then in your controller action you map between the domain model and the view model and you pass the view model to the view:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            Badge badge = ...
            BasgeViewModel vm = new BasgeViewModel
            {
                Id = badge.Id,
                Name = badge.Name
            };
    
            return Json(vm, JsonRequestBehavior.AllowGet);
        }
    }
    

    and if you are sick of writing mapping code in your controllers you simply head over to your NuGet package console and type the following command:

    Install-Package AutoMapper
    

    in order to take full advantage of the excellent AutoMapper library.

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

Sidebar

Related Questions

I have a Sinatra server that is returning multiple JSON objects from the database
I have a service returning an array of type BaseItem. BaseItem has N subtypes.
I have Django project on Dreamhost server which has several views that returns Json
I have a WCF service in an ASP.NET AJAX app that is returning json.
I have a jqGrid calling a controller action (returning JSON to jqGrid). When my
I have a restful WCF service that is returning JSON. I was wondering how
I have JSON objects returning form the server and markers created for them. On
I have a web service that is returning JSON. When testing the program, either
I have a situation where I'm returning json objects to my application which are
I have Json returning as the following: [{CreatedBy:GIS_DB,CreatedDate:3/8/2012 10:44:00 AM,Id:39,ModifiedBy:,ModifiedDate:,Name:CF-39,StatusId:1,TrailCoordinates:[{CreatedBy:GIS_DB,CreatedDate:3/8/2012 10:44:00 AM,Id:1637,Latitude:32.76004207,Longitude:-97.34006853,ModifiedBy:,ModifiedDate:,SortOrder:1,TrailId:39},{CreatedBy:GIS_DB,CreatedDate:3/8/2012 10:44:00 AM,Id:1638,Latitude:32.76004333,Longitude:-97.34012121,ModifiedBy:,ModifiedDate:,SortOrder:2,TrailId:39}]},{CreatedBy:GIS_DB,CreatedDate:3/8/2012

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.