I have the following code in my controller where I send the list of cities to a JsonResult
private ApplicationDbContext db = new ApplicationDbContext();
//la linea anterior es donde instancio el modelo de datos o data context
public JsonResult GetDataCiudades()
{
var CiudadesJson = db.ciudad.ToListAsync(); // from model
return Json(CiudadesJson, JsonRequestBehavior.AllowGet);
}
And when I try to return this JsonResult from the view I use the following code ...
else {
$('#Ciudad').find('option').remove();
$.ajax({
type: "POST",
url: '@Url.Action("GetDataCiudades", "GenerarCertificado")',
dataType: 'json',
type: 'POST',
data: "{}",
contentType: 'application/json',
success: function (data) {
var result = JSON.parse(data);
$.each(result, function (index, value) {
var option = $('<option value="' + index + '">' + value + '</option>');
$('#Ciudad').append(option);
});
},
error: function (data, status, jqXHR) {
alert('Error al cargar Ciudades.');
}
});
}
But it returns a lot of objects and characters in the drop-down list that I'm showing in the view ....
What am I doing wrong?