{"id":54,"date":"2025-10-08T09:55:07","date_gmt":"2025-10-08T07:55:07","guid":{"rendered":"https:\/\/kaurpakaste24.thkit.ee\/wp\/?page_id=54"},"modified":"2025-10-20T15:37:32","modified_gmt":"2025-10-20T13:37:32","slug":"students-controller-mudel-ja-view","status":"publish","type":"page","link":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/students-controller-mudel-ja-view\/","title":{"rendered":"Students Controller, Model ja View"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Controller<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The SchoolContext _context tells the Controller and View what the database looks like and all the information inside it.\n\nIndex lets us view all the Students information in general using the ToListAsync() method which puts all the books into a table.\n\nCreate first gives us the Create view and then once the information is given, it checks that the model is correct and if so, adds it to the database and takes you back to the Index.\n\nIt also uses SaveChangesAsync to save the information\n\nDelete deletes the given selection after checking that it exists. It first uses FirstorDefaultAsync which returns the first element of the array asynchronously. And uses the Lambda method to briefly show the anonymous method.\n\nAnd then saves it to the database after deleting the selected object.\n\nDetails lets us view more detailed information about the given object. It also uses the FirstorDefaultAsync and Lambda methods.\n\nEdit lets us modify the given object. It uses the FirstorDefaultAsync and Lambda methods. It also has a post method which then saves everything that was changed.\n\nClone allows us to make a copy of a given object. It uses FirstorDefaultAsync and a Lambda method to pass information to the view and save it after the copy is made.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing System.Threading.Tasks;\nusing Microsoft.AspNetCore.Mvc;\nusing Microsoft.EntityFrameworkCore;\nusing Microsoft.IdentityModel.Tokens;\nusing TallinnaRakenduslikKolledzKaur.Data;\nusing TallinnaRakenduslikKolledzKaur.Models;\n\nnamespace TallinnaRakenduslikKolledzKaur.Controllers\n{\n    public class StudentsController : Controller\n    {\n        private readonly SchoolContext _context;\n        public StudentsController(SchoolContext context) \n        {\n            _context = context;\n        }\n        public async Task&lt;IActionResult&gt; Index()\n        {\n            return View(await _context.Students.ToListAsync());\n        }\n        &#x5B;HttpGet]\n        public IActionResult Create()\n        {\n            return View();\n        }\n        \/\/\/ &lt;summary&gt;\n        \/\/\/  Lisa uus student\n        \/\/\/ &lt;\/summary&gt;\n        \/\/\/ &lt;param name=&quot;student&quot;&gt;&lt;\/param&gt;\n        \/\/\/ &lt;returns&gt;&lt;\/returns&gt;\n        &#x5B;HttpPost]\n        &#x5B;ValidateAntiForgeryToken]\n        public async Task&lt;IActionResult&gt; Create(&#x5B;Bind(&quot;Id, LastName,FirstName,EnrollmentDate,Commendments&quot;)] Student student)\n        {\n            if (ModelState.IsValid)\n            {\n                _context.Students.Add(student);\n                await _context.SaveChangesAsync();\n                return RedirectToAction(&quot;Index&quot;);\n                \/\/ return RedirectToAction(nameof(Index))\n            }\n            return View(student);\n        }\n        \/\/\/ &lt;summary&gt;\n        \/\/\/  Get delete view for student\n        \/\/\/ &lt;\/summary&gt;\n        \/\/\/ &lt;param name=&quot;Id&quot;&gt;id of student&lt;\/param&gt;\n        \/\/\/ &lt;returns&gt;&lt;\/returns&gt;\n        &#x5B;HttpGet]\n        public async Task&lt;IActionResult&gt; Delete(int? Id)\n        {\n            if (Id == null)\n            {\n                return NotFound();\n            }\n            var student = await _context.Students.FirstOrDefaultAsync(m =&gt; m.Id == Id);\n            if (student == null) \n            {\n                return NotFound();\n            }\n            return View(student);\n        }\n        &#x5B;HttpPost, ActionName(&quot;Delete&quot;)]\n        &#x5B;ValidateAntiForgeryToken]\n        public async Task&lt;IActionResult&gt; DeleteConfirmed(int? Id)\n        {\n            var student = await _context.Students.FindAsync(Id);\n            _context.Students.Remove(student);\n            await _context.SaveChangesAsync();\n            return RedirectToAction(&quot;Index&quot;);\n        }\n        &#x5B;HttpGet]\n        public async Task&lt;IActionResult&gt; Details(int? Id)\n        {\n            if (Id == null)\n            {\n                return NotFound();\n            }\n            var student = await _context.Students.FirstOrDefaultAsync(m =&gt; m.Id == Id);\n            if (student == null)\n            {\n                return NotFound();\n            }\n            return View(student);\n        }\n                     &#x5B;HttpGet]\n        public async Task&lt;IActionResult&gt;Edit(int? Id)\n        {\n            if (Id == null)\n            {\n                return NotFound();\n            }\n            var student = await _context.Students.FirstOrDefaultAsync(m =&gt; m.Id == Id);\n            if (student == null)\n            {\n                return NotFound();\n            }\n            _context.Students.Update(student);\n            return View(student);\n        }\n        &#x5B;HttpPost, ActionName(&quot;Edit&quot;)]\n        &#x5B;ValidateAntiForgeryToken]\n        public async Task&lt;IActionResult&gt; EditConfirmed(&#x5B;Bind(&quot;Id,LastName,FirstName,EnrollmentDate,Commendments&quot;)] Student student)\n        {\n            _context.Students.Update(student);\n            await _context.SaveChangesAsync();\n            return RedirectToAction(&quot;Index&quot;);\n        }\n        &#x5B;HttpGet]\n        public async Task&lt;IActionResult&gt; Clone(int? Id)\n        {\n            if (Id == null)\n            {\n                return NotFound();\n            }\n            var student = await _context.Students.FirstOrDefaultAsync(m =&gt; m.Id == Id);\n            if (student == null)\n            {\n                return NotFound();\n            }\n            return View(student);\n        }\n        &#x5B;HttpPost, ActionName(&quot;Clone&quot;)]\n        &#x5B;ValidateAntiForgeryToken]\n        public async Task&lt;IActionResult&gt; CloneConfirmed(int? Id)\n        {\n            var student = await _context.Students.FirstOrDefaultAsync(m =&gt; m.Id == Id);\n            \/\/ModelState.Remove(&quot;Id&quot;);\n            if (ModelState.IsValid)\n            {\n                _context.Students.Add(student);\n                await _context.SaveChangesAsync();\n                return RedirectToAction(&quot;Index&quot;);\n                \/\/ return RedirectToAction(nameof(Index))\n            }\n            return View(student);\n        }\n    }\n}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Mudel<\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing System.ComponentModel.DataAnnotations;\n\nnamespace TallinnaRakenduslikKolledzKaur.Models\n{\n    public class Student\n    {\n        &#x5B;Key]\n        public int Id { get; set; }\n        public string FirstName { get; set; }\n        public string LastName { get; set; }\n        public ICollection&lt;Enrollment&gt;? Enrollments { get; set; }\n        public DateTime EnrollmentDate { get; set; }\n\n        public int? GPA { get; set; }\n        public ICollection&lt;Commendation&gt;? Commendations { get; set; } \/* Kiitused *\/\n        public ICollection&lt;Mark&gt;? Marks { get; set; } \/* M\u00e4rkused *\/\n\n\n\n    }\n}\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">View<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Clone<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n@model TallinnaRakenduslikKolledzKaur.Models.Student\n\n@{\n\tViewData&#x5B;&quot;Title&quot;] = &quot;Copy \u00f5pilane&quot;;\n}\n\n&lt;h1&gt;Copy \u00f5pilane&lt;\/h1&gt;\n&lt;hr \/&gt;\n&lt;div&gt;\n\t&lt;h4&gt;\u00d5pilane @Model.FirstName @Model.LastName&lt;\/h4&gt;\n\t&lt;hr \/&gt;\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.LastName)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.LastName)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.FirstName)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.FirstName)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.EnrollmentDate)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.EnrollmentDate)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.Commendations)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.Commendations)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.Enrollments)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.Enrollments)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\n\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.Marks)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.Marks)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\n&lt;\/div&gt;\n&lt;form asp-action=&quot;Clone&quot;&gt;\n\t&lt;input type=&quot;hidden&quot; asp-for=&quot;Id&quot; \/&gt;\n\t&lt;input type=&quot;submit&quot; asp-route-id=&quot;Id&quot;value=&quot;Clone&quot; class=&quot;btn btn-primary&quot; \/&gt; | &lt;a asp-action=&quot;Index&quot;&gt;T\u00fchista&lt;\/a&gt;\n&lt;\/form&gt;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Create<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n@model TallinnaRakenduslikKolledzKaur.Models.Student\n\n@{\n\tViewData&#x5B;&quot;Title&quot;] = &quot;Loo uus \u00f5pilane&quot;;\n}\n\n&lt;h1&gt;Loo uus \u00f5pilane&lt;\/h1&gt;\n&lt;hr\/&gt;\n&lt;div class=&quot;row&quot;&gt;\n\t&lt;div class=&quot;col-md-4&quot;&gt;\n\t\t&lt;form asp-action=&quot;Create&quot;&gt;\n\n\t\t\t&lt;div asp-validation-summary=&quot;ModelOnly&quot; class=&quot;text-danger&quot;&gt;&lt;\/div&gt;\n\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;label asp-for=&quot;LastName&quot; class=&quot;control-label&quot;&gt;&lt;\/label&gt;\n\t\t\t\t&lt;input asp-for=&quot;LastName&quot; class=&quot;form-control&quot; \/&gt;\n\t\t\t\t&lt;span asp-validation-for=&quot;LastName&quot; class=&quot;text-danger&quot;&gt;&lt;\/span&gt;\n\t\t\t&lt;\/div&gt;\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;label asp-for=&quot;FirstName&quot; class=&quot;control-label&quot;&gt;&lt;\/label&gt;\n\t\t\t\t&lt;input asp-for=&quot;FirstName&quot; class=&quot;form-control&quot; \/&gt;\n\t\t\t\t&lt;span asp-validation-for=&quot;FirstName&quot; class=&quot;text-danger&quot;&gt;&lt;\/span&gt;\n\t\t\t&lt;\/div&gt;\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;label asp-for=&quot;EnrollmentDate&quot; class=&quot;control-label&quot;&gt;&lt;\/label&gt;\n\t\t\t\t&lt;input asp-for=&quot;EnrollmentDate&quot; class=&quot;form-control&quot; \/&gt;\n\t\t\t\t&lt;span asp-validation-for=&quot;EnrollmentDate&quot; class=&quot;text-danger&quot;&gt;&lt;\/span&gt;\n\t\t\t&lt;\/div&gt;\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;label asp-for=&quot;Commendations&quot; class=&quot;control-label&quot;&gt;&lt;\/label&gt;\n\t\t\t\t&lt;input asp-for=&quot;Commendations&quot; class=&quot;form-control&quot; \/&gt;\n\t\t\t\t&lt;span asp-validation-for=&quot;Commendations&quot; class=&quot;text-danger&quot;&gt;&lt;\/span&gt;\n\t\t\t&lt;\/div&gt;\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;input type=&quot;submit&quot; value=&quot;Sisesta&quot; class=&quot;btn btn-primary&quot;\/&gt;\n\t\t\t&lt;\/div&gt;\n\t\t&lt;\/form&gt;\n\t&lt;\/div&gt;\n&lt;\/div&gt;\n\t\t\n&lt;div&gt;\n\t&lt;a asp-action=&quot;Index&quot;&gt;Mine tagasi loendisse&lt;\/a&gt;\n&lt;\/div&gt;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Delete<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n@model TallinnaRakenduslikKolledzKaur.Models.Student\n\n@{\n\tViewData&#x5B;&quot;Title&quot;] = &quot;Kustuta \u00f5pilane&quot;;\n}\n\n&lt;h1&gt;Kustuta \u00f5pilane&lt;\/h1&gt;\n&lt;h3&gt;\n\tKas oled kindel et tahad \u00f5pilast @Model.FirstName @Model.LastName eemaldada?\n&lt;\/h3&gt;\n&lt;div&gt;\n\t&lt;h4&gt;\u00d5pilane @Model.FirstName @Model.LastName&lt;\/h4&gt;\n\t&lt;hr \/&gt;\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.LastName)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.LastName)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.FirstName)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.FirstName)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.EnrollmentDate)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.EnrollmentDate)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.Commendations)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.Commendations)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\n\n\t@if (Model.Enrollments != null)\n\t{\n\t\tforeach (var Enrollments in Model.Enrollments)\n\t\t{\n\t\t\t&lt;dl class=&quot;row&quot;&gt;\n\t\t\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.Enrollments)&lt;\/dt&gt;\n\t\t\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.Enrollments)&lt;\/dd&gt;\n\t\t\t&lt;\/dl&gt;\n\t\t}\n\t}\n\t@if (Model.Marks != null)\n\t{\n\t\tforeach (var Marks in Model.Marks)\n\t\t{\n\t\t\t&lt;dl class=&quot;row&quot;&gt;\n\t\t\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.Marks)&lt;\/dt&gt;\n\t\t\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.Marks)&lt;\/dd&gt;\n\t\t\t&lt;\/dl&gt;\n\t\t}\n\t}\n&lt;\/div&gt;\n\n&lt;form asp-action=&quot;Delete&quot;&gt;\n\t&lt;input type=&quot;hidden&quot; asp-for=&quot;Id&quot;\/&gt;\n\t&lt;input type=&quot;submit&quot; value=&quot;Kustuta \u00f5pilane&quot; class=&quot;btn btn-danger&quot;\/&gt; | &lt;a asp-action=&quot;Index&quot;&gt;T\u00fchista&lt;\/a&gt;\n&lt;\/form&gt;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Details<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n@model TallinnaRakenduslikKolledzKaur.Models.Student\n\n@{\n\tViewData&#x5B;&quot;Title&quot;] = &quot;Viewing \u00f5pilane&quot;;\n}\n\n&lt;div&gt;\n\t&lt;h4&gt;\u00d5pilane @Model.FirstName @Model.LastName&lt;\/h4&gt;\n\t&lt;hr \/&gt;\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.LastName)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.LastName)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.FirstName)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.FirstName)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.EnrollmentDate)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.EnrollmentDate)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.Commendations)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.Commendations)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.Enrollments)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.Enrollments)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\n\n\t&lt;dl class=&quot;row&quot;&gt;\n\t\t&lt;dt class=&quot;col-sm-2&quot;&gt;@Html.DisplayNameFor(Model =&gt; Model.Marks)&lt;\/dt&gt;\n\t\t&lt;dd class=&quot;col-sm-10&quot;&gt;@Html.DisplayFor(Model =&gt; Model.Marks)&lt;\/dd&gt;\n\t&lt;\/dl&gt;\n\n&lt;\/div&gt;\n\n\n&lt;form asp-action=&quot;Tagasi&quot;&gt;\n\t&lt;input type=&quot;hidden&quot; asp-for=&quot;Id&quot; \/&gt;\n\t&lt;a asp-action=&quot;Index&quot;&gt;Tagasi&lt;\/a&gt;\n&lt;\/form&gt;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Edit<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n@model TallinnaRakenduslikKolledzKaur.Models.Student\n\n@{\n\tViewData&#x5B;&quot;Title&quot;] = &quot;Muuda \u00f5pilane&quot;;\n}\n\n&lt;h1&gt;Muuda \u00f5pilane&lt;\/h1&gt;\n&lt;hr \/&gt;\n&lt;div class=&quot;row&quot;&gt;\n\t&lt;div class=&quot;col-md-4&quot;&gt;\n\t\t&lt;form asp-action=&quot;Edit&quot;&gt;\n\n\t\t\t&lt;div asp-validation-summary=&quot;ModelOnly&quot; class=&quot;text-danger&quot;&gt;&lt;\/div&gt;\n\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;label asp-for=&quot;LastName&quot; class=&quot;control-label&quot;&gt;&lt;\/label&gt;\n\t\t\t\t&lt;input asp-for=&quot;LastName&quot; class=&quot;form-control&quot; \/&gt;\n\t\t\t\t&lt;span asp-validation-for=&quot;LastName&quot; class=&quot;text-danger&quot;&gt;&lt;\/span&gt;\n\t\t\t&lt;\/div&gt;\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;label asp-for=&quot;FirstName&quot; class=&quot;control-label&quot;&gt;&lt;\/label&gt;\n\t\t\t\t&lt;input asp-for=&quot;FirstName&quot; class=&quot;form-control&quot; \/&gt;\n\t\t\t\t&lt;span asp-validation-for=&quot;FirstName&quot; class=&quot;text-danger&quot;&gt;&lt;\/span&gt;\n\t\t\t&lt;\/div&gt;\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;label asp-for=&quot;EnrollmentDate&quot; class=&quot;control-label&quot;&gt;&lt;\/label&gt;\n\t\t\t\t&lt;input asp-for=&quot;EnrollmentDate&quot; class=&quot;form-control&quot; \/&gt;\n\t\t\t\t&lt;span asp-validation-for=&quot;EnrollmentDate&quot; class=&quot;text-danger&quot;&gt;&lt;\/span&gt;\n\t\t\t&lt;\/div&gt;\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;label asp-for=&quot;Commendations&quot; class=&quot;control-label&quot;&gt;&lt;\/label&gt;\n\t\t\t\t&lt;input asp-for=&quot;Commendations&quot; class=&quot;form-control&quot; \/&gt;\n\t\t\t\t&lt;span asp-validation-for=&quot;Commendations&quot; class=&quot;text-danger&quot;&gt;&lt;\/span&gt;\n\t\t\t&lt;\/div&gt;\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;label asp-for=&quot;Marks&quot; class=&quot;control-label&quot;&gt;&lt;\/label&gt;\n\t\t\t\t&lt;input asp-for=&quot;Marks&quot; class=&quot;form-control&quot; \/&gt;\n\t\t\t\t&lt;span asp-validation-for=&quot;Marks&quot; class=&quot;text-danger&quot;&gt;&lt;\/span&gt;\n\t\t\t&lt;\/div&gt;\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;label asp-for=&quot;Enrollments&quot; class=&quot;control-label&quot;&gt;&lt;\/label&gt;\n\t\t\t\t&lt;input asp-for=&quot;Enrollments&quot; class=&quot;form-control&quot; \/&gt;\n\t\t\t\t&lt;span asp-validation-for=&quot;Enrollments&quot; class=&quot;text-danger&quot;&gt;&lt;\/span&gt;\n\t\t\t&lt;\/div&gt;\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;label asp-for=&quot;GPA&quot; class=&quot;control-label&quot;&gt;&lt;\/label&gt;\n\t\t\t\t&lt;input asp-for=&quot;GPA&quot; class=&quot;form-control&quot; \/&gt;\n\t\t\t\t&lt;span asp-validation-for=&quot;GPA&quot; class=&quot;text-danger&quot;&gt;&lt;\/span&gt;\n\t\t\t&lt;\/div&gt;\n\t\t\t&lt;div class=&quot;form-group&quot;&gt;\n\t\t\t\t&lt;input type=&quot;submit&quot; value=&quot;Edit&quot; class=&quot;btn btn-primary&quot; \/&gt;\n\t\t\t&lt;\/div&gt;\n\t\t&lt;\/form&gt;\n\t&lt;\/div&gt;\n&lt;\/div&gt;\n\n&lt;div&gt;\n\t&lt;a asp-action=&quot;Index&quot;&gt;Mine tagasi loendisse&lt;\/a&gt;\n&lt;\/div&gt;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Index<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n@model IEnumerable&lt;TallinnaRakenduslikKolledzKaur.Models.Student&gt;\n@{\n\tViewData&#x5B;&quot;Title&quot;] = &quot;\u00d5pilased&quot;;\n}\n&lt;h1&gt;\u00d5pilaste Loend:&lt;\/h1&gt;\n&lt;p&gt;\n\t&lt;a asp-action=&quot;Create&quot;&gt;Sisesta \u00d5pilane&lt;\/a&gt;\n&lt;\/p&gt;\n&lt;table class=&quot;table&quot;&gt;\n\t&lt;thead&gt;\n\t\t&lt;tr&gt;\n\t\t\t&lt;th&gt;\n\t\t\t\t@Html.DisplayNameFor(Model =&gt; Model.LastName)\n\t\t\t&lt;\/th&gt;\n\t\t\t&lt;th&gt;\n\t\t\t\t@Html.DisplayNameFor(Model =&gt; Model.FirstName)\n\t\t\t&lt;\/th&gt;\n\t\t\t&lt;th&gt;\n\t\t\t\t@Html.DisplayNameFor(Model =&gt; Model.EnrollmentDate)\n\t\t\t&lt;\/th&gt;\n\t\t\t&lt;th&gt;\n\t\t\t\t@Html.DisplayNameFor(Model =&gt; Model.GPA)\n\t\t\t&lt;\/th&gt;\n\t\t\t&lt;th&gt;T\u00f6\u00f6riistad&lt;\/th&gt;\n\t\t&lt;\/tr&gt;\n\t&lt;\/thead&gt;\n\t&lt;tbody&gt;\n\t\t@foreach (var student in Model)\n\t\t{\n\t\t\t&lt;tr&gt;\n\t\t\t\t&lt;td&gt;\n\t\t\t\t\t@Html.DisplayFor(modelItem =&gt; student.LastName)\n\t\t\t\t&lt;\/td&gt;\n\t\t\t\t&lt;td&gt;\n\t\t\t\t\t@Html.DisplayFor(modelItem =&gt; student.FirstName)\n\t\t\t\t&lt;\/td&gt;\n\t\t\t\t&lt;td&gt;\n\t\t\t\t\t@Html.DisplayFor(modelItem =&gt; student.EnrollmentDate)\n\t\t\t\t&lt;\/td&gt;\n\t\t\t\t&lt;td&gt;\n\t\t\t\t\t@Html.DisplayFor(modelItem =&gt; student.GPA)\n\t\t\t\t&lt;\/td&gt;\n\t\t\t\t&lt;td&gt;\n\t\t\t\t\t&lt;a asp-action=&quot;Edit&quot; asp-route-id=&quot;@student.Id&quot;&gt;Muuda&lt;\/a&gt;\n\t\t\t\t&lt;\/td&gt;\n\t\t\t\t&lt;td&gt;\n\t\t\t\t\t&lt;a asp-action=&quot;Details&quot; asp-route-id=&quot;@student.Id&quot;&gt;Vaata&lt;\/a&gt;\n\t\t\t\t&lt;\/td&gt;\n\t\t\t\t&lt;td&gt;\n\t\t\t\t\t&lt;a asp-action=&quot;Delete&quot; asp-route-id=&quot;@student.Id&quot;&gt;Kustuta&lt;\/a&gt;\n\t\t\t\t&lt;\/td&gt;\n\t\t\t\t&lt;!--&lt;td&gt;\n\t\t\t\t\t&lt;a asp-action=&quot;Clone&quot; asp-route-id=&quot;@student.Id&quot;&gt;Clone&lt;\/a&gt;\n\t\t\t\t&lt;\/td&gt;  --&gt;\n\t\t\t&lt;\/tr&gt;\n\t\t}\n\t&lt;\/tbody&gt;\n&lt;\/table&gt;\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Controller The SchoolContext _context tells the Controller and View what the database looks like and all the information inside it. Index lets us view all the Students information in general using the ToListAsync() method which puts all the books into a table. Create first gives us the Create view and then once the information is given, it checks that the model is correct and if so, adds it to the database and takes you back to the Index. It also uses SaveChangesAsync to save the information Delete deletes the given selection after checking that it exists. It first uses FirstorDefaultAsync which returns the first element of the array asynchronously. And uses the Lambda method to briefly show the anonymous method. And then saves it to the database after deleting the selected object. Details lets us view more detailed information about the given object. It also uses the FirstorDefaultAsync and Lambda methods. Edit lets us modify the given object. It uses the FirstorDefaultAsync and Lambda methods. It also has a post method which then saves everything that was changed. Clone allows us to make a copy of a given object. It uses FirstorDefaultAsync and a Lambda method to pass information to the view and save it after the copy is made. Mudel View Clone Create Delete Details Edit Index<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-54","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Students Controller, Model ja View - Kaur portfoolio \/ English<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/students-controller-mudel-ja-view\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Students Controller, Model ja View - Kaur portfoolio \/ English\" \/>\n<meta property=\"og:description\" content=\"Controller The SchoolContext _context tells the Controller and View what the database looks like and all the information inside it. Index lets us view all the Students information in general using the ToListAsync() method which puts all the books into a table. Create first gives us the Create view and then once the information is given, it checks that the model is correct and if so, adds it to the database and takes you back to the Index. It also uses SaveChangesAsync to save the information Delete deletes the given selection after checking that it exists. It first uses FirstorDefaultAsync which returns the first element of the array asynchronously. And uses the Lambda method to briefly show the anonymous method. And then saves it to the database after deleting the selected object. Details lets us view more detailed information about the given object. It also uses the FirstorDefaultAsync and Lambda methods. Edit lets us modify the given object. It uses the FirstorDefaultAsync and Lambda methods. It also has a post method which then saves everything that was changed. Clone allows us to make a copy of a given object. It uses FirstorDefaultAsync and a Lambda method to pass information to the view and save it after the copy is made. Mudel View Clone Create Delete Details Edit Index\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/students-controller-mudel-ja-view\/\" \/>\n<meta property=\"og:site_name\" content=\"Kaur portfoolio \/ English\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-20T13:37:32+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kaurpakaste24.thkit.ee\\\/wp\\\/eng\\\/students-controller-mudel-ja-view\\\/\",\"url\":\"https:\\\/\\\/kaurpakaste24.thkit.ee\\\/wp\\\/eng\\\/students-controller-mudel-ja-view\\\/\",\"name\":\"Students Controller, Model ja View - Kaur portfoolio \\\/ English\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kaurpakaste24.thkit.ee\\\/wp\\\/eng\\\/#website\"},\"datePublished\":\"2025-10-08T07:55:07+00:00\",\"dateModified\":\"2025-10-20T13:37:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kaurpakaste24.thkit.ee\\\/wp\\\/eng\\\/students-controller-mudel-ja-view\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kaurpakaste24.thkit.ee\\\/wp\\\/eng\\\/students-controller-mudel-ja-view\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kaurpakaste24.thkit.ee\\\/wp\\\/eng\\\/students-controller-mudel-ja-view\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/kaurpakaste24.thkit.ee\\\/wp\\\/eng\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Students Controller, Model ja View\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kaurpakaste24.thkit.ee\\\/wp\\\/eng\\\/#website\",\"url\":\"https:\\\/\\\/kaurpakaste24.thkit.ee\\\/wp\\\/eng\\\/\",\"name\":\"Kaur portfoolio \\\/ English\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/kaurpakaste24.thkit.ee\\\/wp\\\/eng\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Students Controller, Model ja View - Kaur portfoolio \/ English","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/students-controller-mudel-ja-view\/","og_locale":"en_US","og_type":"article","og_title":"Students Controller, Model ja View - Kaur portfoolio \/ English","og_description":"Controller The SchoolContext _context tells the Controller and View what the database looks like and all the information inside it. Index lets us view all the Students information in general using the ToListAsync() method which puts all the books into a table. Create first gives us the Create view and then once the information is given, it checks that the model is correct and if so, adds it to the database and takes you back to the Index. It also uses SaveChangesAsync to save the information Delete deletes the given selection after checking that it exists. It first uses FirstorDefaultAsync which returns the first element of the array asynchronously. And uses the Lambda method to briefly show the anonymous method. And then saves it to the database after deleting the selected object. Details lets us view more detailed information about the given object. It also uses the FirstorDefaultAsync and Lambda methods. Edit lets us modify the given object. It uses the FirstorDefaultAsync and Lambda methods. It also has a post method which then saves everything that was changed. Clone allows us to make a copy of a given object. It uses FirstorDefaultAsync and a Lambda method to pass information to the view and save it after the copy is made. Mudel View Clone Create Delete Details Edit Index","og_url":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/students-controller-mudel-ja-view\/","og_site_name":"Kaur portfoolio \/ English","article_modified_time":"2025-10-20T13:37:32+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/students-controller-mudel-ja-view\/","url":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/students-controller-mudel-ja-view\/","name":"Students Controller, Model ja View - Kaur portfoolio \/ English","isPartOf":{"@id":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/#website"},"datePublished":"2025-10-08T07:55:07+00:00","dateModified":"2025-10-20T13:37:32+00:00","breadcrumb":{"@id":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/students-controller-mudel-ja-view\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/students-controller-mudel-ja-view\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/students-controller-mudel-ja-view\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/"},{"@type":"ListItem","position":2,"name":"Students Controller, Model ja View"}]},{"@type":"WebSite","@id":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/#website","url":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/","name":"Kaur portfoolio \/ English","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/wp-json\/wp\/v2\/pages\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":2,"href":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/wp-json\/wp\/v2\/pages\/54\/revisions"}],"predecessor-version":[{"id":198,"href":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/wp-json\/wp\/v2\/pages\/54\/revisions\/198"}],"wp:attachment":[{"href":"https:\/\/kaurpakaste24.thkit.ee\/wp\/eng\/wp-json\/wp\/v2\/media?parent=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}