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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:37:53+00:00 2026-05-22T02:37:53+00:00

Guys, I’m havin a problem with this… My User class has a property UserType

  • 0

Guys, I’m havin a problem with this…

My User class has a property UserType userType like below:

    public class User
{
    public virtual int  Id { get; set; }
    public virtual string User { get; set; }
    public virtual string Name { get; set; }
    public virtual UserType userType { get; set; }
}

I can’t return a JSON, like this…

[HttpGet]
    public JsonResult JSONUsers(string q)
    {
        IEnumerable<User> model = dataServ.Users.GetUsers( q );
        return this.Json( new { Result = model }, JsonRequestBehavior.AllowGet );
    }

I’m getting an error:

A circular reference was detected
while serializing an object of type
‘System.Reflection.RuntimeModule’.

The reason I’m getting this error is the Lazy-Load (at least that’s what I understood), and to poorly solve it, I did:

public JsonResult JSON(string q)
    {
        List<User> model = new List<User>();
        IEnumerable<User> users= dataServ.Users.Getusers( q );

        foreach (var item in users)
        {
            User user = new User
            {
                Id = item.Id,
                Name = item.Name
            };
            model.Add( user );
        };

        return this.Json( new { Result = model }, JsonRequestBehavior.AllowGet );
    }

I don’t think this is a good solution. In this case I only need de “Id” and “Name” properties, but what if I need all properties? Will I have to copy one by one?
Can Anybody tell me if there is a better solution?

Thanks,

Thiago

  • 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-22T02:37:54+00:00Added an answer on May 22, 2026 at 2:37 am

    Ayende wrote a great series of blog posts about this problem.

    But to summarize: USE VIEW MODELS => and by the way that’s the solution to more than half of the questions on StackOverflow about ASP.NET MVC that I am answering.

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

Sidebar

Related Questions

Guys if I have class like below: template<class T> class X { T** myData_;
Guys, I've came across this problem I can't resolve myselg, I'm pretty sure I
Guys, I am very new to c++. I have just wrote this class: class
Guys Please help me to solve this floating problem.I tried different methods but anything
Guys I asked a similar question like this earlier since I was unable to
guys i have a xml file which is like this: <Point TestFlag=0 id=1 name=Conversation
Guys, what is function called after my class loaded, where i can call self
guys i have arrays in which i have to match this kind of text
Guys, I am using dynamic programming approach to solve a problem. Here is a
Guys, I know this is going to turn out to be a simple answer,

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.