bind modal to row click in datatable - html

Helo,
i have a datatable that contains data from my database. in each row there is a details button. i want on button click to open a modal with the details of the clicked rows.
i tried to create instance of modals for each row on page load but it is slowing down the website.
is there a way to populate a modal according to a row ID?
this is my table
<table id="tblMessagesDetail" class="table table table-hover table-striped table-condensed export-table" style="width: 100%;">
<thead>
<tr>
<th>
#*#Html.DisplayNameFor(model => model.SmsList[0].SmsMT.Id)*#
#ViewRes.SharedStrings.SmsID
</th>
<th>
#*#Html.DisplayNameFor(model => model.SmsList[0].SmsMT.Account.Project.Customer.Name)*#
#ViewRes.SharedStrings.CustomerName
</th>
<th>
#*#Html.DisplayNameFor(model => model.SmsList[0].SmsMT.Account.Project.Name)*#
#ViewRes.SharedStrings.ProjectName
</th>
<th>
#*#Html.DisplayNameFor(model => model.SmsList[0].SmsMT.Account.Login)*#
#ViewRes.SharedStrings.Account
</th>
<th>
#Html.DisplayNameFor(model => model.SmsList[0].MSISDN)
</th>
<th>
#*#Html.DisplayNameFor(model => model.SmsList[0].SmsMT.SmsStatus.Value)*#
#ViewRes.SharedStrings.smsStatus
</th>
<th>
#Html.DisplayNameFor(model => model.SmsList[0].SmsMT.EventReason)
</th>
<th>
#*#Html.DisplayNameFor(model => model.SmsList[0].SendDate)*#
#ViewRes.SharedStrings.SendDate
</th>
<th>
#*#Html.DisplayNameFor(model => model.SmsList[0].SmsMT.SentDate)*#
#ViewRes.SharedStrings.SentDate
</th>
<th>
#Html.DisplayNameFor(model => model.SmsList[0].SmsMT.Ticket)
</th>
<th>
#Html.DisplayNameFor(model => model.SmsList[0].ExtId)
</th>
<th>
#Html.DisplayNameFor(model => model.SmsList[0].SmsMTContent.NotificationLevel)
</th>
<th>
#Html.DisplayNameFor(model => model.SmsList[0].SmsMTContent.OADC)
</th>
<th>
#Html.DisplayNameFor(model => model.SmsList[0].SmsMTContent.Message)
</th>
<th>
</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model.SmsList)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.Id)
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.Account.Project.Customer.Name)
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.Account.Project.Name)
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.Account.NMGLogin)
</td>
<td>
#Html.DisplayFor(modelItem => item.MSISDN)
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.SmsStatus.Value)
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.EventReason)
</td>
<td>
#Html.DisplayFor(modelItem => item.SendDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.SentDate)
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.Ticket)
</td>
<td>
#Html.DisplayFor(modelItem => item.ExtId)
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMTContent.NotificationLevel)
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMTContent.OADC)
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMTContent.Message)
</td>
<!-- Button trigger modal -->
<td>
#*#using (Html.BeginForm("FillDetailModal", "Statistics", FormMethod.Post))
{*#
<button id="btnDetails" type="submit" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#myModal-#item.SmsMTId">
<i class="glyphicon glyphicon-th-list"></i> #ViewRes.SharedStrings.btnDetails
</button>
</td>
</tr>
}
</tbody>
and this is my modal
<div class="modal fade" draggable="true" id="myModal-#item.SmsMTId" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div id="modalDialog" draggable="true" class="modal-dialog" style="padding-bottom:0px">
<div class="modal-content">
<div class="modal-header" style="background-color: #428bca; color: white; ">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
Message Detail ID: '#item.SmsMTId' - Ticket ##item.SmsMT.Ticket - Project #item.SmsMT.Account.Project.Name
</h4>
</div>
<div class="modal-body" style="padding: 0px;">
<table style="width:100%;" class="table table table-hover table-striped table-condensed export-table" border="0">
<tr>
<td align="left">
<label>#ViewRes.SharedStrings.SmsID</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.Id)
</td>
</tr>
<tr>
<td align="left">
<label>#ViewRes.SharedStrings.CustomerName</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.Account.Project.Customer.Name)
</td>
</tr>
<tr>
<td align="left">
<label> #ViewRes.SharedStrings.ProjectName</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.Account.Project.Name)
</td>
</tr>
<tr>
<td align="left">
<label>#ViewRes.SharedStrings.Account</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.Account.NMGLogin)
</td>
</tr>
<tr>
<td align="left">
<label> #Html.DisplayNameFor(model => model.SmsList[0].MSISDN)</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.MSISDN)
</td>
</tr>
<tr>
<td align="left">
<label>#ViewRes.SharedStrings.smsStatus</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.SmsStatus.Value)
</td>
</tr>
<tr>
<td align="left">
<label>#ViewRes.SharedStrings.EventReason</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.EventReason)
</td>
</tr>
<tr>
<td align="left">
<label>#ViewRes.SharedStrings.SendDate</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SendDate)
</td>
</tr>
<tr>
<td align="left">
<label>#ViewRes.SharedStrings.SentDate</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.SentDate)
</td>
</tr>
<tr>
<td align="left">
<label>#ViewRes.SharedStrings.TicketId</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMT.Ticket)
</td>
</tr>
<tr>
<td align="left">
<label>#ViewRes.SharedStrings.ExternalID</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.ExtId)
</td>
</tr>
<tr>
<td align="left">
<label style="width:160px;">#ViewRes.SharedStrings.NotificationLevel</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMTContent.NotificationLevel)
</td>
</tr>
<tr>
<td align="left">
<label> #Html.DisplayNameFor(model => model.SmsList[0].SmsMTContent.OADC)</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMTContent.OADC)
</td>
</tr>
<tr>
<td align="left">
<label>#Html.DisplayNameFor(model => model.SmsList[0].SmsMTContent.Message)</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMTContent.Message)
</td>
</tr>
<tr>
<td align="left">
<label> #ViewRes.SharedStrings.binaryMessage</label>
</td>
<td>
#Html.DisplayFor(modelItem => item.SmsMTContent.Binary)
</td>
</tr>
</table>
</div>
<div class="modal-footer" style="margin: 0px; padding: 9px 30px 10px;">
<button type="button" class="btn btn-default" data-dismiss="modal">
#ViewRes.SharedStrings.btnClose
</button>
</div>
</div>
</div>
</div>
how can i pass the value of the row and then do a link wuery on the database to extract the appropriate data?
I appreciate any help i can get

You can actually bind your id to data-whatever attribute and put it in a table row or even in a column.
<tr data-toggle="modal" data-target="#myModalIdHere" data-whatever="myDataIdHere">
in jQuery:
$('#myModalIdHere').on('show.bs.modal', function (event) {
// this is the trigger
var tableRow = $(event.relatedTarget);
// get myDataIdHere to data-whatever attribute
var myDataIdHere = tableRow.data('whatever');
// updating modal's content
// bind myDataIdHere to myInputIdHere
var modal = $(this);
modal.find('.modal-body #myInputIdHere').val(myDataIdHere);
});

Query all data and put icons in the last column using while loop. With this u can create a table with all your data and the icons will serve us the buttons for your view, delete or edit
while($row = $sql->fetch()){
$id = $row['id'];
$company = $row['company_name'];
$domain = $row['domain_name'];
$industry = $row['industry_type'];
$websitet = $row['website_type'];
$websitep = $row['website_purpose'];
$audience = $row['target_audience'];
$web_pages = $row['web_pages'];
$color = $row['color_scheme'];
$style = $row['style'];
$addons = $row['addons'];
$url = $row['url_of_existing'];
$like_dislike = $row['like_dislike_existing_website'];
$sample = $row['sample_website'];
echo '<tr><td>'.$id.'</td>';
echo '<td>'.$company.'</td>';
echo '<td>'.$domain.'</td>';
echo '<td>'.$industry.'</td>';
echo '<td><img src=img/view.png width=20px height=20px id="view"></td>';
echo '<td><img src="img/delete.png" width=20px height=20px name="delete"></td></tr>';
?>
the <a href...?id='.$id.'" part is to send the id using the get method.. look it up if you dont know about it.. pretty much this will solve your problem.

Related

How do I change the status in a field when a button is clicked using a script

When a person clicks the addressed link on a status report that is marked "ContainsErrors" I would like it to change the status to "Accepted". It is my first time writing a script, can someone help me with that? The below script does nothing.
Where they would click to change the status:
<a id="addressed" asp-route-id="#item.BatchHeaderId" style="text-decoration:underline">Addressed</a>
This is the script so far:
<script>
$('#addressed').click(function(){
if($(this).data('BatchProcessStatusCode')=="ContainErrors"){
$("#BatchProcessStatusCode").val("Accepted");
});
});
Any help is much appreciated. Thank you
Updated
<div class="row box-shadow--6dp" style="margin-top:20px; margin-left:0px; margin-right:0px; border:solid; border-width:1px; padding-top:10px;">
<form asp-controller="Batch" asp-action="Explorer" method="get">
<table class="spaced-table">
<tr>
#if (HttpContextAccessor.HttpContext.Session.GetString("FacilityIdentifier") != "")
{
<td>
<input asp-for="FacilityIdentifier" type="hidden" value="#HttpContextAccessor.HttpContext.Session.GetString("FacilityIdentifier")" readonly />
</td>
}
else
{
<td><label>Facility Name:</label></td>
<td><select asp-for="FacilityIdentifier" asp-items="#ViewBag.FacilityIdentifier" style="height:22px;width:300px;"><option></option></select></td>
}
</tr>
<tr>
<td><label>Batch Status:</label></td>
<td><select asp-for="BatchProcessStatusCode" asp-items="#ViewBag.BatchProcessStatusCode" style="height:22px;width:300px;"><option></option></select></td>
</tr>
<tr>
<td><label>From Date:</label></td>
<td><input asp-for="FromDate" type="date" style="height:22px;width:300px;" /></td>
</tr>
<tr>
<td><label>To Date:</label></td>
<td><input asp-for="ToDate" type="date" style="height:22px;width:300px;" /><br /><span asp-validation-for="ToDate" style="font-size:0.9em;color:red;"></span></td>
</tr>
</table>
<div style="float:right; margin-bottom: 10px;">
<button id="BatchExplorerSearch" class="btn btn-sm btn-primary" type="submit">Search</button>
<a asp-action="Explorer" class="btn btn-sm btn-secondary">Clear</a>
</div>
</form>
</div>
<div class="box-shadow--6dp table-container-search">
<div class="row" style="font-weight:bold; margin-right:0px;">
<div class="col-9">
Batch Explorer Results:
#if (Model.BatchHeader.Count() == 0)
{
<div class="alert alert-info">No records found!</div>
}
</div>
<div class="col-3">
#if (Model.BatchHeader.Count() > 1 && Model.BatchHeader.Count() != 0)
{
<span>#Model.BatchHeader.Count() Batches Found</span>
}
else
{
<span>#Model.BatchHeader.Count() Batch Found</span>
}
</div>
</div>
<div class="scrolling-region">
#foreach (var item in Model.BatchHeader)
{
#if (item.BatchProcessStatusCode == "Accepted")
{
<table class="table-sm table-borderless box-shadow--6dp condensed-table table-card table-3col" style="background-color: cornsilk;">
<tbody>
<tr>
<td>
#Html.DisplayFor(model => model.Facility.FirstOrDefault(x => x.FacilityIdentifier == item.FacilityIdentifier).FacilityName)
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<a asp-action="Summary" asp-route-id="#item.BatchHeaderId" style="text-decoration:underline">
#Html.DisplayFor(model => item.BatchIdentifier)
</a>
</td>
<td>
Services Reported: #item.PgnetEncounterBatchDetails.Count()
</td>
<td>
Submission Date: #Html.DisplayFor(model => item.CreateDate)
</td>
</tr>
<tr>
<td>
Status: #Html.DisplayFor(model => item.BatchProcessStatusCodeNavigation.BatchProcessStatusLabel)
</td>
<td>
Errors Found: #item.BatchErrorDetails.Count()
</td>
<td>
<a asp-action="FileDetails" asp-route-id="#item.BatchHeaderId" style="text-decoration:underline">Source File</a>
</td>
<td></td>
</tr>
</tbody>
</table>
}
else if (item.BatchProcessStatusCode == "ContainsErrors")
{
<table class="table-sm table-borderless box-shadow--6dp condensed-table table-card table-3col" style="background-color: salmon;">
<tbody>
<tr>
<td>
#Html.DisplayFor(model => model.Facility.FirstOrDefault(x => x.FacilityIdentifier == item.FacilityIdentifier).FacilityName)
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<a asp-action="Summary" asp-route-id="#item.BatchHeaderId" style="text-decoration:underline">
#Html.DisplayFor(model => item.BatchIdentifier)
</a>
</td>
<td>
Services Reported: #item.PgnetEncounterBatchDetails.Count()
</td>
<td>
Submission Date: #Html.DisplayFor(model => item.CreateDate)
</td>
</tr>
<tr>
<td>
Status: #Html.DisplayFor(model => item.BatchProcessStatusCodeNavigation.BatchProcessStatusLabel)
</td>
<td>
Errors Found: #item.BatchErrorDetails.Count()
</td>
<td>
<a asp-action="FileDetails" asp-route-id="#item.BatchHeaderId" style="text-decoration:underline">Source File</a> |
<a asp-action="Explorer" asp-route-id="#item.BatchHeaderId" name="addressed" style="text-decoration:underline">Addressed</a>
</td>
</tr>
</tbody>
</table>
}
else if (item.BatchProcessStatusCode == "Withdrawn")
{
<table class="table-sm table-borderless box-shadow--6dp condensed-table table-card table-3col" style="background-color: gray;">
<tbody>
<tr>
<td>
#Html.DisplayFor(model => model.Facility.FirstOrDefault(x => x.FacilityIdentifier == item.FacilityIdentifier).FacilityName)
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<a asp-action="Summary" asp-route-id="#item.BatchHeaderId" style="text-decoration:underline">
#Html.DisplayFor(model => item.BatchIdentifier)
</a>
</td>
<td>
Services Reported: #item.PgnetEncounterBatchDetails.Count()
</td>
<td>
Submission Date: #Html.DisplayFor(model => item.CreateDate)
</td>
</tr>
<tr>
<td>
Status: #Html.DisplayFor(model => item.BatchProcessStatusCodeNavigation.BatchProcessStatusLabel)
</td>
<td>
Errors Found: #item.BatchErrorDetails.Count()
</td>
<td>
<a asp-action="FileDetails" asp-route-id="#item.BatchHeaderId" style="text-decoration:underline">Source File</a>
</td>
</tr>
</tbody>
</table>
}
else
{
<table class="table-sm table-borderless box-shadow--6dp condensed-table table-card table-3col">
<tbody>
<tr>
<td>
#Html.DisplayFor(model => model.Facility.FirstOrDefault(x => x.FacilityIdentifier == item.FacilityIdentifier).FacilityName)
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<a asp-action="Summary" asp-route-id="#item.BatchHeaderId" style="text-decoration:underline">
#Html.DisplayFor(model => item.BatchIdentifier)
</a>
</td>
<td>
Services Reported: #item.PgnetEncounterBatchDetails.Count()
</td>
<td>
Submission Date: #Html.DisplayFor(model => item.CreateDate)
</td>
</tr>
<tr>
<td>
Status: #Html.DisplayFor(model => item.BatchProcessStatusCodeNavigation.BatchProcessStatusLabel)
</td>
<td>
Errors Found: #item.BatchErrorDetails.Count()
</td>
<td>
<a asp-action="FileDetails" asp-route-id="#item.BatchHeaderId" style="text-decoration:underline">Source File</a> |
Addressed
</td>
</tr>
</tbody>
</table>
}
}
</div>
</div>

Angular 5 disable a table row

This is my HTML code for my table to display list of users:
<table class="table m-table m-table--head-bg-metal">
<thead>
<tr>
<th>
Nom
</th>
<th>
Prénom
</th>
<th>
Email
</th>
<th>
Action
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Jhon
</td>
<td>
Stone
</td>
<td>
jhonStone#gmail.com
</td>
<td>
<button class="btn btn-outline-danger m-btn m-btn--icon btn-sm m-btn--icon-only m-btn--pill m-btn--air" (click)="onDisableUser()">
<i class="fa fa-close"></i>
</button>
</td>
</tr>
</tbody>
This is typescript method:
onDisableUser(){
//this is the method to disable the table row..
}
What I want is when I click () on the action button, the table row will be disabled.
Thanks in advance.
What do you mean with disable?
If you want to remove the list item do this on the html :
<table class="table m-table m-table--head-bg-metal">
<thead>
<tr>
<th>
Nom
</th>
<th>
Prénom
</th>
<th>
Email
</th>
<th>
Action
</th>
</tr>
</thead>
<tbody>
<tr *ngIf="!isDisable">
<td>
Jhon
</td>
<td>
Stone
</td>
<td>
jhonStone#gmail.com
</td>
<td>
<button class="btn btn-outline-danger m-btn m-btn--icon btn-sm m-btn--icon-only m-btn--pill m-btn--air" (click)="onDisableUser()">
<i class="fa fa-close"></i>
</button>
</td>
</tr>
</tbody>
</table>
And on the typescript:
isDisable = false;
onDisableUser(){
this.isDisable = true;
}
If you want to disable it with css use this in html:
<tr [ngClass]="{'disabled': isDisable}>
You can use the css method to disable the table row.
Set the disabled to true when clicked and set the class to the <tr> if disabled=true
.disable{
cursor: not-allowed;
}
<table>
<tr class="disable">
<td> akjsd </td>
</tr>
<tr >
<td> akjsd </td>
</tr>
</table>
isDisable = false;
onDisableUser(){
this.isDisable = true;
}

Pass html datalist value to Html.Action

I'm creating an HTML form that lists line items from one organization that need to be mapped to another on. My idea was to take the id of the selected option, and pass that to the action via Html.Action. This is the code I have so far;
<table class="table">
<tr>
<th>
#Html.DisplayNameFor(model => model.newID)
</th>
<th>
#Html.DisplayNameFor(model => model.oldserviceid)
</th>
<th>
#Html.DisplayNameFor(model => model.description)
</th>
<th>
#Html.DisplayNameFor(model => model.Avg)
</th>
<th>
#Html.DisplayNameFor(model => model.Count)
</th>
<th>
#Html.DisplayNameFor(model => model.acquisitionid)
</th>
<th></th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
#* This is where I'm stuck *#
<form action=#Html.Action("Update", new { linemappingID = #item.LineMapID, newID = /*what goes here?*/ }) method="post" onsubmit="return updateForm()" id="#item.LineMapID">
<input list="serviceList" name="serviceList">
<datalist id="serviceList">
#foreach (var serv in ViewBag.serviceList)
{
#* Pass the ID value from here to the Html.Action *#
<option value="#serv.serviceid - #serv.servicedesc" id="#serv.serviceid">#serv.serviceid - #serv.servicedesc</option>
}
</datalist>
<input type="submit" value="update" />
</form>
</td>
<td>
#Html.DisplayFor(modelItem => item.oldserviceid)
</td>
<td>
#Html.DisplayFor(modelItem => item.description)
</td>
<td>
$#Html.DisplayFor(modelItem => item.Avg)
</td>
<td>
#Html.DisplayFor(modelItem => item.Count)
</td>
<td>
#Html.DisplayFor(modelItem => item.acquisitionid)
</td>
</tr>
}
</table>

Checkbox Deactiving Rows by ID (View/Controller) in MVC 5

I have a table in my view with a column of Checkboxes. I want the user to be able to select as many Checkboxes as they'd like and click a button at the bottom to deactivate them (Users in this model can be suspended/deactivated and reinstated/activated). I don't have any errors, but nothing is happening when I click on the buttons. I attached my code below. Thanks.
View
#using (Html.BeginForm("CheckBoxDeactivate"))
{
<table class="table">
<tr>
<th>
Select Users
</th>
<th>
#Html.DisplayNameFor(model => model.ID)
</th>
<th>
#Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
#Html.DisplayNameFor(model => model.LastName)
</th>
<th>
#Html.DisplayNameFor(model => model.Email)
</th>
<th>
#Html.DisplayNameFor(model => model.UserName)
</th>
<th>
#Html.DisplayNameFor(model => model.suspended)
</th>
<th></th>
</tr>
#foreach (var item in Model) {
<tr>
<td>
<input type= "checkbox" name="manageUsers" value="#item.ID" />
</td>
<td>
#Html.DisplayFor(modelItem => item.ID)
</td>
<td>
#Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
#Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
#Html.DisplayFor(modelItem => item.Email)
</td>
<td>
#Html.DisplayFor(modelItem => item.UserName)
</td>
<td>
#Html.DisplayFor(modelItem => item.suspended)
</td>
</tr>
}
</table>
<br />
<input type="button" value="Add Roles" onclick="location.href'#Url.Action("CheckBoxDeactivate", "User")'" />
Controller
[HttpPost]
public ActionResult CheckBoxDeactivate(int[] ids)
{
tbl_Reg_User OAWUser = new tbl_Reg_User();
foreach (var id in ids)
{
OAWUser = db.tbl_Reg_User.Single(o => o.ID == id);
OAWUser.suspended = true;
db.SaveChanges();
}
ViewBag.Message = "Users deactivated successfully!";
return View();
}
<input type= "checkbox" name="manageUsers" value="#item.ID" />
This line should be
<input type= "checkbox" name="ids" id="ids" value="#item.ID" />
I think you are not getting the selected checkboxes in controller.
View
#using (Html.BeginForm("CheckBoxDeactivate","Home"))
{
<table class="table" border="1" style="border:1px solid black;border-collapse:collapse;">
<tr>
<th>Select Users
</th>
<th>
Sr.No.
</th>
<th>
FirstName
</th>
<th>
LastName
</th>
<th>
Phone
</th>
<th>
IsActive
</th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
<input type= "checkbox" name="ids" id="ids" value="#item.Sr_No" />
</td>
<td>
#item.Sr_No
</td>
<td>
#item.FirstName
</td>
<td>
#item.LastName
</td>
<td>
#item.Phone
</td>
<td>
#item.IsActive
</td>
</tr>
}
</table>
<br />
<input type="submit" value="Add Roles" onclick="#Url.Action("CheckBoxDeactivate", "User")" />
}
Controller
[HttpPost]
public ActionResult CheckBoxDeactivate(int[] ids)
{
Temp OAWUser = new Temp();
if (ids != null)
{
foreach (var id in ids)
{
//Your code goes here
}
ViewBag.Message = "Users deactivated successfully!";
}
return RedirectToAction("Temp");
}
This piece of code did the job for me

Create paging in HTML table

I have Html code that generates a table that contains a lot of records.
Here is the code:
#model IEnumerable<UserContact>
#{
ViewBag.Title = "Contacts:";
}
<h2>
Contacts</h2>
<table>
<tr>
<th>
#Html.DisplayText("First Name")
</th>
<th>
#Html.DisplayText("First Name")
</th>
<th>
#Html.DisplayText("Email")
</th>
<th>
</th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
#Html.CheckBox("misha", new { onclick = "this.form.submit();" })
</td>
<td>
#Html.DisplayFor(modelItem => item.firstName)
</td>
<td>
#Html.DisplayFor(modelItem => item.lastName)
</td>
<td>
#Html.DisplayFor(modelItem => item.email)
</td>
</tr>
}
</table>
This code is contained in razor partial view page.
My question is how can I create paging in table that described above?
As per your comment i m showing complete example of datatable here :
Jquery and CSS References :-
Links :-
http://code.jquery.com/jquery-1.11.1.min.js
http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js
http://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css
Your Partial View :-
#model IEnumerable<UserContact>
#{
ViewBag.Title = "Contacts:";
}
<h2>
Contacts</h2>
<table id="mydatatable">
<thead>
<tr>
<th>
#Html.DisplayText("First Name")
</th>
<th>
#Html.DisplayText("First Name")
</th>
<th>
#Html.DisplayText("Email")
</th>
<th>
</th>
</tr>
<thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>
#Html.CheckBox("misha", new { onclick = "this.form.submit();" })
</td>
<td>
#Html.DisplayFor(modelItem => item.firstName)
</td>
<td>
#Html.DisplayFor(modelItem => item.lastName)
</td>
<td>
#Html.DisplayFor(modelItem => item.email)
</td>
</tr>
}
<tbody>
</table>
<script type="text/javascript">
$(document).ready(function(){
$('#mydatatable').dataTable();
});
</script>
Last but not the least don't forget to add references of required jquery files on your page.
//cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css
//cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js
/////////////////////////////////////
<table id="myTable">
<tr>
<th>
#Html.DisplayText("First Name")
</th>
<th>
#Html.DisplayText("First Name")
</th>
<th>
#Html.DisplayText("Email")
</th>
<th>
</th>
</tr>
#foreach (var item in Model)
{
<tr>
<td>
#Html.CheckBox("misha", new { onclick = "this.form.submit();" })
</td>
<td>
#Html.DisplayFor(modelItem => item.firstName)
</td>
<td>
#Html.DisplayFor(modelItem => item.lastName)
</td>
<td>
#Html.DisplayFor(modelItem => item.email)
</td>
</tr>
}
</table>
<script type="text/javascript">
$(document).ready(function(){
$('#myTable').dataTable();
});
</script>