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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:26:09+00:00 2026-05-26T06:26:09+00:00

I defined a model like this public class Planilla { [Key] public int IDPlanilla

  • 0

I defined a model like this

public class Planilla
{
    [Key]
    public int IDPlanilla { get; set; }

    [Required(ErrorMessage = "*")]
    [Display(Name = "Dirección de Negocio")]
    public int IDDireccionDeNegocio { get; set; }

    [Required (ErrorMessage = "*")]
    public string Nombre { get; set; }
    [Display(Name = "Descripción")]
    public string Descripcion { get; set; }

    public bool Activo { get; set; }

    [ScriptIgnore]
    public virtual DireccionDeNegocio DireccionDeNegocio { get; set; }
}

And I have a method in my controller that returns the first element of this model

    [HttpPost]
    public ActionResult GetElements(string IDCampana)
    {
        Planilla query = db.Planillas.First();
        return Json(query);                 
    }

My problem is when I invoke this method from client side throws an error that say’s

circular reference is detected trying to serialize
System.Data.Entity.DynamicProxies.Planilla_7F7D4D6D9AD7AEDCC59865F32D5D02B4023989FC7178D7698895D2CA59F26FEE
Debugging my code I realized that the object returned by the execution
of the method
Firstit's a
{System.Data.Entity.DynamicProxies.Planilla_7F7D4D6D9AD7AEDCC59865F32D5D02B4023989FC7178D7698895D2CA59F26FEE}
instead a Model of my namespace like
Example.Models.DireccionDeNegocio`.

Why am I doing wrong?? Because I tried with other models and work’s well

  • 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-26T06:26:10+00:00Added an answer on May 26, 2026 at 6:26 am

    Use view models, that’s the only advice I can give you. Never pass domain models to your views. It’s as simple as that. And if you respect this simple rule and fundamental rule in ASP.NET MVC applications you will never have problems. So for example if you need only the id and the description in your view:

    [HttpPost]
    public ActionResult GetElements(string IDCampana)
    {
        Planilla query = db.Planillas.First();
        return Json(new 
        { 
            Id = query.IDPlanilla, 
            Description = query.Description 
        });
    }
    

    Notice that in this case the anonymous object serves as view model. But if you really wanted to do things properly you would write your view model:

    public class PlanillaViewModel
    {
        public int Id { get; set; }
        public string Description { get; set; }
    }
    

    and then:

    [HttpPost]
    public ActionResult GetElements(string IDCampana)
    {
        Planilla query = db.Planillas.First();
        return Json(new PlanillaViewModel 
        { 
            Id = query.IDPlanilla, 
            Description = query.Description 
        });
    }
    

    By the way Ayende wrote a nice series of blog posts about this.

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

Sidebar

Related Questions

I have a model like this defined... public class Product{ private long timestamp; //
So I have defined a model like this: class Model extends Zend_Db_Table_Abstract { $_primary
My simplified domain model looks something like this: public abstract class Entity<IdK> { public
I have a model class like this: namespace Models { public struct Localization {
I have a model that looks something like this: public class SampleModel { public
I had View strongly type of my class Usario Defined like this public partial
I have defined some models like this (Entity Framework Code-First): public class A {
I have joined models like this: // /foo/lib/model/doctrine/PurchasedItemTable.class.php public function retrievePurchased(Doctrine_Query $q) { $rootAlias
I have a model defined this way class Lga < ActiveRecord::Base validates_uniqueness_of :code validates_presence_of
Lets say I have model inheritance set up in the way defined below. class

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.