Como puedo mandar una lista a un select con MVC
No me muestra nada que puedo hacer?
Tengo mi codigo HTML:
@{
ViewBag.Title = "Index";
}
<body onload="combo()">
<div class="container body-content">
<h5><span>Selecciona una Opcion:</span></h5>
<select id="id" name="id_xxx" class="form-control dropdown-toggle" onchange="combo"></select>
</div>
<script src="~/JS/XXXXX.js"></script>
</body>
codigo JS
function combo() {
var x = document.getElementById("id");
$.ajax({
type: "POST",
url: 'GetCombo',
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
console.log(response);
}
});
}
controller
public class xxxxx: Controller
{
// GET: XXXX
public ActionResult Index()
{
return View();
}
public List<combo> GetCombo()
{
List<combo> lista = new List<combo>();
lista.Add(new combo()
{
idOption = ""
});
using (var contex = new XXXXXXEntities())
{
var query = from s in contex.XXXXXX orderby s.XXXXX ascending select new { s.X, s.X };
foreach (var item in query.ToList())
{
int X = Convert.ToInt32(item.X);
lista.Add(new combo()
{
X = X,
idOption = item.idOption.ToString()
}); ;
}
}
return lista;
}
}