I'm returning a object from controller to view, but it doesn't always work. It does not work when the object contains a list of objects, if the list is empty it works (the html rData3 is updated with text).
1 - The object that I'm returning:
public class Etiqueta
{
public int Id { get; set; }
public string Nombre { get; set; }
public List<EtiquetaFoto> EtiquetasFotos { get; set; }
}
2 - The Controller:
public class FotosController : Controller
{
public JsonResult Etiqueta(string Id)
{
var sa = new JsonSerializerSettings();
Etiqueta etiq = _context.Etiquetas.Where(x => (x.Id.ToString() == Id)).Include(x => x.EtiquetasFotos).First();
return Json(etiq,sa);
}
}
3 - The View:
<script type="text/jscript">
$("button").click(function () {
var cID = $(this).attr('id');
$.getJSON('/Fotos/Etiqueta/' + cID, function (data) {
var items = "";
items += data.Id + " - " + data.Nombre;
$('#rData3').html(items);
});
})
</script>
What I should do to it works when the object has the list EtiquetasFotos with data?