Controller variable is null in ajax get

0

I have List of objects that is instantiated when the view is created, when a value in the dropdownlist is selected, I use ajax to make a request to check which of the objects within that List is the corresponding dropdownlist . The problem is that this List is null in the ajax method

public class HomeController : Controller
{
    List<Lanche> lanches = new List<Lanche>();

    ...

    public IActionResult Index()
    {    
        PopularListaLanches(lanches);
    }

    [HttpGet("GetIngredientes")]
    public JsonResult GetIngredientes(int id)
    {
        var lanche = lanches.Where(x => (int)x.NomeLanche == id).FirstOrDefault();

        return Json(lanche);
    }

Is there a way to persist this data in the user session?

    
asked by anonymous 16.04.2018 / 18:19

0 answers