I want to fill out a dropdwonlist with a stored procedure.
My procedure is as follows:
CREATE PROCEDURE GetDepartamentos
AS
BEGIN
SELECT 0 Id_Departamento, 'Todos' Nombre_Departamento
UNION ALL
SELECT Id_Departamento, Nombre_Departamento FROM Departamentos
END
I have already mapped my procedure with entityframework and created a model GetDepartamentos_Result.cs
Now in my controller I have a method that returns a List:
public List<GetDepartamentos_Result> GetDepartamentos()
{
using (TigerEntities db = new TigerEntities())
{
var v = db.GetDepartamentos().ToList();
return v;
}
}
And an ActionResult combo method that sends me Combo.cshtml
view:
public ActionResult Combo()
{
var a = GetDepartamentos();
ViewBag.Departamentos = new SelectList(a, "Id_Departamento", "Nombre_Departamento");
return View();
}
Is it correct what I am doing to fill the combo? I have not managed to get it and also as I would call it in view?
@model List
I hope you can give me some guidance on this.
Thank you very much for your help.