Мой контролер:
Код: Выделить всё
namespace Seminar5.Controllers
{
public class SeminarController : Controller
{
public IActionResult Apply()
{
return View();
}
[HttpPost]
public IActionResult Apply(UserInfo model)
{
Repository.CreateUser(model);
return View("Thanks",model);
}
public IActionResult List()
{
return View();
}
public IActionResult Details(int id)
{
return View(Repository.TakeId(id));
}
Код: Выделить всё
public class UserInfo
{
public int Id { get; set; }
public string? Name { get; set; }
public string? Phone { get; set; }
public string? Email { get; set; }
public bool WillAttend { get; set; }
}
Код: Выделить всё
public class Repository
{
private static List _users = new();
public static List Users
{
get
{
return _users;
}
}
static Repository()
{
_users.Add(new KullaniciBilgi() { Id = 1, Name = "Busra", Email = "[email protected]", Phone = "111111111", WillAttend = true });
_users.Add(new KullaniciBilgi() { Id = 2, Name = "Nur", Email = "[email protected]", Phone = "8384388438", WillAttend = true });
_users.Add(new KullaniciBilgi() { Id = 3, Name = "Busra", Email = "[email protected]", Phone = "3438848384", WillAttend = true });
}
public static void CreateUser(UserInfo user)
{
_users.Add(user);
user.Id = Users.Count + 1;
}
public static UserInfo? IdAl(int id)
{
return _users.FirstOrDefault(user => user.Id == id);
}
}
}
Код: Выделить всё
@model List
@{
ViewBag.Title = "Status of Participating Into Seminar";
}
Seminar Participation List
Name
Email
Participance Status
@{
int i = 0;
}
@foreach(var user in Model)
{
var status = user.WillAttend == true ? "Evet" : "Hayır";
var classname = user.WillAttend == true ? "table-success" : "table-danger";
if(user.WillAttend==true)
{
i++;
@user.Name
@status
[url=/seminer/details/@user.Id]Detail[/url]
}
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... etcore-mvc