I want to write a ajax for my view so that if I change the the check box, The RegisterSituation of rows that were chosen is changed in database. my Model is:
public class OstadCourse
{
[Key]
public int OstadCourseId { get; set; }
public int OstadId { get; set; }
public bool RegisterSituation { get; set; }
public string OstadName { get; set; }
public string OstadFamily { get; set; }
public string Title { get; set; }
public int CourseId { get; set; }
}
My View is:(I have tried to add ajax to end of following view, but when I change checked to unchecked, it is send null to controller) How can I write ajax so that change RegisterSituation of rows that change
@model IEnumerable<DataLayer.OstadCourse>
@{
...
var courses = Model.Select(x => new { x.CourseId, x.Title }).Distinct();
var selectedCourseId = Request["selectedCourseId"];
var filteredCourses = String.IsNullOrEmpty(selectedCourseId) ? Model : Model.Where(x => x.CourseId == int.Parse(selectedCourseId));
...
}
<form>
<div class="row">
<div class="col-md-4 mb-3 mb-md-0">
@Html.DropDownList("selectedCourseId", new SelectList(courses, "CourseId", "Title", selectedCourseId), "-- All --", new { @class = "form-control", style = "padding: 0.375rem .75rem;", onchange = "this.form.submit()" })
</div>
</div>
<table class="gridtable">
<thead>
<tr>
<th>Select</th>
<th>Name</th>
<th>Family</th>
</tr>
</thead>
<tbody>
@foreach (var item in filteredCourses)
{
<tr>
<td>
<input type="checkbox" class="rowCheckbox" name="selectedIDs" value="@item.OstadCourseId" @(item.RegisterSituation ? "checked" : "") />
</td>
<td>@item.OstadName</td>
<td>@item.OstadFamily</td>
</tr>
}
</tbody>
</table>
</form>
Aucun commentaire:
Enregistrer un commentaire