Hello for some reason I'm able to add items to a list in one Action method but whenever I pass the list to a view in another method the list appears to be EMPTY. Why is this and could someone explain this? Why is the list empty when it has been added something in another method before?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Hotel.Models;
using System.Diagnostics;
namespace HotelTwee.Controllers
{
public class HomeController : Controller
{
public List<Hotel> preOrders = new List<Hotel>();
public IActionResult Index()
{
// List Count is ZERO here
return View(preOrders);
}
[HttpGet]
public IActionResult Create()
{
return View();
}
[HttpPost]
public IActionResult Create(Hotel order)
{
preOrders.Add(order);
// List COUNT is ONE here
return RedirectToAction("Index", preOrders);
}
}
}
EDIT:
Removing RedirectToAction and using return View("Index", preOrders) has fixed the problem