I have already created a view that displays data in a razor page (5 columns)
studentFirstName, StudentLastName, StudentId, CourseId, Grade
It also displays a button (instead of default Edit link) in each row
@Html.ActionLink("Grade", "Courses", "Students", null, new { @class = "btn btn-success" })
What I would like to do is when the button is clicked, it will navigate to new view (newPage) where a form is displayed (two fields, save button) and gets auto-populated according to the row it was click. What I have done
Added
IActionResult
[HttpGet] public IActionResult Courses(long id) { // get the courses from the collection var Cor = Courselist.Where(c=>c.CourseId == id).FirstOrDefault(); return View(Cor); }
The razor page looks like this (two fields to auto populate
CourseId
andGrade
)@using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal"> <h4>Update Clinical Status</h4> <hr /> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) @Html.HiddenFor(model => model.CourseId) <div class="form-group"> @Html.LabelFor(model => model.CourseId, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.CourseId, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.CourseId, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Grade, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.Grade, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Grade, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" value="Save" class="btn btn-default" /> </div> </div> </div> }
I get the labels and the text fields but not the data (CourseId
, Grade
) from that row, any idea where I went wrong?