• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

196
Vistas
Failing to send data from Action Controller to AJAX Caller ,Serializing context model of a dynamic proxy property

I'm trying to send the queried data gathered from the context back to the ajax caller with the following status

1-The source code server side succeeds querying the data. 2-The source code server side succeeds sending the data in case HTTPPOST or HTTPGET is used 3-No exceptions or errors at the source code 4-applying JSON(queried object) method doesn't make a change The scenario goes as follow:- using ajax call as follows

$.ajax({
                    type: "POST",
                    url: '@Url.Action("MainCatItems", "Cachier")',
                    contentType: "application/json; charset=utf-8",
                    data: datas,
                    dataType: "json",
                    success: successFunc,
                    error: function (xhr) {
                        alert('Error: ' + xhr.statusText);
                    },
                });

calling an Action Controller

[HttpPost]
    public ActionResult MainCatItems(int mainCatNo)
    {
        var results = ......//fetching data from Context
        return Json(new { data = results }, JsonRequestBehavior.AllowGet);
    }

, the call succeeds sending my parameters to the action but sending a response back to the ajax call from the controller is a little bit confusing as I have two cases:

The First: (working perfectly) I'm returning data queried from a table class in my Entity Framework (RegisterNotification Class)

public partial class RegisterNotification
{
    //setters and getters
}

which is a single class with no navigational property declared inside

The Second(where the problem is.) I'm returning data queried from a table class in my Entity Framework (Item Class"partial class")

Part One:-

public *partial* class Item
{
    // setters and getters
}

Part Two:-

 public *partial* class Item
{
    //setters and getters
}

which is a partial class with navigational properties declared inside

This case doesn't work and when getting back to the ajax call it alerts the error function message saying an "internal server error 500" I have tried parsing the queried data to a JSON Object in my controller:-

var t = Json(res,"application/json; charset=utf-8",JsonRequestBehavior.AllowGet);

Queried Data at source code server side Watch:

Client Side error message details

But again with failure. Thanks for concerning.

almost 3 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

set ProxyCreationEnabled to false like this

[HttpPost]
public ActionResult MainCatItems(int mainCatNo)
{
    entity.Configuration.ProxyCreationEnabled = false;
    var results = _model.Item.Where(x => x.MenuCategoryID == mainCatNo).ToList();
    return Json(new { data = results }, JsonRequestBehavior.AllowGet);
}

you are using entity framework generated proxy object which might be causing problems in serializing

almost 3 years ago · Santiago Trujillo Denunciar

0

public JsonResult GetCatItems(int mainCatNo)
    {
        var results = ......//fetching data from Context
        return Json(new { data = results }, JsonRequestBehavior.AllowGet);
    }

Try This .. It might Help You And you can call this method from an action controller.

$.ajax({
                    type: "POST",
                    url: '@Url.Action("GetCatItems", "Cachier")',
                    contentType: "application/json; charset=utf-8",
                    data: datas,
                    dataType: "json",
                    success: successFunc,
                    error: function (xhr) {
                        alert('Error: ' + xhr.statusText);
                    },
                });
almost 3 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda