I am new in MVC.
I have a class in Models like below.
public class UserInfo
{
public string Name{get;set;}
public string Surname{get;set;}
}
And I have a controller like this.
public class HomeController : Controller
{
//
// GET: /Home/
List<UserInfo> Users = new List<UserInfo>();
public ActionResult Index()
{
return View();
}
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(UserInfo userInfo)
{
if (ModelState.IsValid)
{
Users.Add(userInfo);
return RedirectToAction("Index");
}
return View();
}
}
And every time when i press Create button in browser, it redirects to Index View.
But List<UserInfo> is empty. Why it happens? How to save data into List and show from grid or table from that List?