Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Binding Table row textbox and Id, Then save to database

$
0
0

I have an Assessment view that has a table of student populated form a particular class. The table has two separate textboxes added to each of the row

This is the Assessment view

@model  _5._3_EduAdmin.Models.AssessmentViewModel

@using (Html.BeginForm("Assessment", "Student", FormMethod.Post)){


@Html.HiddenFor(m => m.ClassId)<div class="row-fluid"><div class="span8 offset2"><div class="box"><div class="box-content nopadding"><table class="table table-hover table-nomargin table-condensed table-striped"><thead><tr><th>#</th><th>Students Name</th><th>Assessment Score</th><th>Exam Score</th></tr></thead><tbody>
                        @foreach (var item in ViewData["Students"] as IEnumerable<_1._2._0_Core.Domain._2._10_Domain.StudentManagement._10._1_StudentModels.Student>)
                        {
                            int serial = 0;
                            serial++;<tr><td>@serial</td><td>@item.Surname, @item.FirstName @item.MiddleName</td><td class="span3"><div class="controls">
                                        @Html.TextBoxFor(m => m.TestAggregate, new {@class = "input-medium"})</div></td><td class="span3"><div class="controls">
                                        @Html.TextBoxFor(m => m.ExamsScore, new {@class = "input-medium"})</div></td></tr>
                        }</tbody></table></div></div></div></div>
}

Now I want bind each student id to the textbox in that row so that when posting to database I will be able to assign that particular score to the student id in the database, am posting it to another model call Result that has Student id Reference in it.

How do I make it work that way in my controller and then plug it in to my service that saves it to database.

[HttpPost]
    public ActionResult Assessment(AssessmentViewModel model)
    {


            var students = _studentService.getNurStudentbyClass(model.ClassId).Select(x => x.Id);

            foreach (var id in students)
            {
                if (model.ExamsScore == 0)
                {
                    if (model.TestAggregate != 0)
                    {
                        model.ExamsScore = 0;
                        model.TotalScore = model.TestAggregate + model.ExamsScore; 
                        _recordService.CreateResult(model.TestAggregate,model.ExamsScore,model.ExamsScore,model.Grade,model.TermId,model.SubjectId,id,model.SessionId);
                    }
                }

            }
        }

        return View();
    }

this is my controller


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>