How to send 2 lists by JsonResult

0

What I want to do is send 2 lists in a JsonResult method and receive them in Ajax. Because I have a table from many to many, I need to change the IDs by names. So I need you to return the name of things.

public JsonResult GetHerramientas(int ID)
    {
        List<tbl_ListaHerramienta> servicioH = db.tbl_ListaHerramienta.Where(x => x.Id_datos == ID).ToList();
        List<tbl_Herramientas> herramienta = db.tbl_Herramientas.ToList();
        var result = new { Result = servicioH, herramienta };
        return Json(result);
    }

How can I send it and how do I receive it in Ajax?

    
asked by Daisuke Dany 26.06.2018 в 20:36
source

1 answer

1

You can generate an object dictionary and send it in the result.

public ActionResult GetHerramientas(int ID)
        {
            var result = new Dictionary<string, object>();
                result.Add("servicioH ", db.tbl_ListaHerramienta.Where(x => x.Id_datos == ID).ToList());
                result.Add("herramienta ", db.tbl_Herramientas.ToList());                
            return Json(result, JsonRequestBehavior.AllowGet);
        }

Remember to change the control type to ActionResult

    
answered by 26.06.2018 / 21:30
source