How can I change value of angular object used in HTML? - html

I need to change a value in HTML using Angular click. The value is getting changed in the angular function but it is not reflecting in HTML.
My Angularjs and HTML is like :-
$scope.GetTblData = function (Name) {
var Data = $.param({ TblName: Name });
var MyTblDataList = [];
$scope.TempName = '';
$scope.TempName = Name;
if (Name == 'ContactTbl') {
$('#ContactTbl').show();
$('#CourseTbl').hide();
$('#CourseDescTbl').hide();
$('#CourseSubDescTbl').hide();
$('#InternTbl').hide();
$('#LocationTbl').hide();
}
else if (Name == 'CourseTbl') {
$('#ContactTbl').hide();
$('#CourseTbl').show();
$('#CourseDescTbl').hide();
$('#CourseSubDescTbl').hide();
$('#InternTbl').hide();
$('#LocationTbl').hide();
}
else if (Name == 'CourseDescTbl') {
$('#ContactTbl').hide();
$('#CourseTbl').hide();
$('#CourseDescTbl').show();
$('#CourseSubDescTbl').hide();
$('#InternTbl').hide();
$('#LocationTbl').hide();
}
else if (Name == 'CourseSubDesc') {
$('#ContactTbl').hide();
$('#CourseTbl').hide();
$('#CourseDescTbl').hide();
$('#CourseSubDescTbl').show();
$('#InternTbl').hide();
$('#LocationTbl').hide();
}
else if (Name == 'InternTbl') {
$('#ContactTbl').hide();
$('#CourseTbl').hide();
$('#CourseDescTbl').hide();
$('#CourseSubDescTbl').hide();
$('#InternTbl').show();
$('#LocationTbl').hide();
}
else if (Name == 'LocationTbl') {
$('#ContactTbl').hide();
$('#CourseTbl').hide();
$('#CourseDescTbl').hide();
$('#CourseSubDescTbl').hide();
$('#InternTbl').hide();
$('#LocationTbl').show();
}
$http({
url: '/Admin/FetchTblData',
method: 'POST',
data: Data,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
}
}).success(function (data) {
$scope.MyTblDataList = data;
}).error(function (data) {
alert('Cannot Load Table data')
});
}//GetTblData End
<li ng-repeat="r in MyTblList">
<a href="#" data-ng-click="GetTblData(r.TblName)">
<i class="glyphicon glyphicon-ok"></i>
{{r.TblName}}
</a>
</li>
<h2>{{TempName}} Details</h2>
<div class="table-responsive">
<table id="CourseTbl" class="table table-hover table-bordered" style="margin:0px 5px; width:1070px">
<thead style="background-color:aqua">
<tr>
<td>
S. No.
</td>
<td>
ID
</td>
<td>
Name
</td>
<td>
Description
</td>
<td>
Image
</td>
<td>
CourseLink
</td>
<td>
Action
</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="r in MyTblDataList">
<td>
{{$index+1}}
</td>
<td>
{{r.ID}}
</td>
<td>
{{r.Name}}
</td>
<td>
{{r.Description}}
</td>
<td>
<img src="~/img/course-img/{{r.Img}}" height="200px" width="200px" />
#*{{r.Img}}*#
</td>
<td>
{{r.CourseLink}}
</td>
<td>
<div class="btn btn-group-xs">
<input type="button" class="btn btn-lg btn-info" ng-click="editItem(r.ID)" value="Edit" />
<input type="button" class="btn btn-xs btn-danger" value="Delete" />
</div>
</td>
</tr>
</tbody>
</table>
</div>
But the problem is that on click of the anchor tag the value of $scope.TempName changes in Angularjs function but value of {{TempName}} doesn't change.

Related

Sort table rows by ASC, DESC (different type of content per column)

I have this function:
function sortTable(index) {
var table, rows, switching, i, x, y, shouldSwitch, array = [];
table = $("table");
switching = true;
while (switching) {
switching = false;
rows = table.find("tbody tr:not(.table-extra-hidden)");
for (i = 0; i < (rows.length); i++) {
shouldSwitch = false;
x = rows.eq(i).find("td").eq(index);
y = rows.eq(i + 1).find("td").eq(index);
if(sortOrder == "desc" && x.find('.primary-info').text().replace(/[^a-zA-Z0-9 _]/g,'') < y.find('.primary-info').text().replace(/[^a-zA-Z0-9 _]/g,''))
{
shouldSwitch = true;
break;
}
else
{
shouldSwitch = true;
break;
}
}
if (shouldSwitch) {
if(sortOrder == "asc")
{
rows.eq(i).insertBefore(rows.eq(i-1));
}
else
{
rows.eq(i).insertAfter(table.find("tr:not(.table-extra-hidden)").last());
}
switching = true;
}
}
}
The click event:
$(window).on("load", function(){
$("a").click(function(e){
if($(this).attr("href") == "#")
{
e.preventDefault();
e.stopPropagation();
}
if($(this).closest("th").length)
{
$("th").not($(this).closest("th")).find("a").removeClass("is-sorted sort-desc sort-asc")
if($(this).hasClass("is-sorted"))
{
if($(this).hasClass("sort-desc"))
{
$(this).removeClass("sort-desc").addClass("sort-asc");
}
else
{
$(this).removeClass("sort-asc").addClass("sort-desc");
}
}
else
{
$(this).addClass("is-sorted sort-desc");
}
//get table column index.
var index = $(this).closest("th").index();
var switching, table, rows, x, y, shouldSwitch;
if($(this).hasClass("sort-desc"))
{
sortOrder = "desc";
}
else if($(this).hasClass("sort-asc"))
{
sortOrder = "asc";
}
sortTable(index);
}
}
It's used to sort this table:
<table>
<thead>
<tr>
<th>Date</th>
<th>Amount</th>
<th>Trade</th>
<th class="no-pointer"></th>
</tr>
</thead>
<tbody>
<tr data-paired="1" tabindex="0">
<td>
<b>Bitcoin Buy</b>
<br />
<span class="primary-info">Jan 21, 2022</span>
</td>
<td>
<b class="primary-info">$1,800.00</b>
<br>
<span>0.00035678 BTC at $34,557.80</span>
</td>
<td>
<span class="primary-info">Trade</span>
</td>
<td class="expandable-trigger">
<a href="#">
<span class="icon icon-sm" data-icon-name="chevron-down"></span>
</a>
</td>
</tr>
<tr class="table-extra-hidden" data-paired="1">
<td>
<b>Status</b>
<br>
<span>Filled</span>
<br><br>
<b>Filed</b>
<br>
<span>Jan 1, 2022, 6:31 AM EST</span>
</td>
<td>
<b>Paid With</b>
<br>
<span>20.00000000 GUSD</span>
</td>
<td></td>
<td></td>
</tr>
<tr data-paired="2" tabindex="0">
<td>
<b class="buy-option">Dogecoin Buy</b>
<br />
<span class="primary-info">Jan 20, 2022</span>
</td>
<td>
<b class="primary-info">$50.00</b>
<br>
<span class="converstion-option">0.00035678 BTC at $34,557.80</span>
</td>
<td>
<span class="primary-info">Trade</span>
</td>
<td class="expandable-trigger">
<a href="#">
<span class="icon icon-sm" data-icon-name="chevron-down"></span>
</a>
</td>
</tr>
<tr data-paired="3" tabindex="0">
<td>
<b class="buy-option">Bitcoin Trade</b>
<br />
<span class="primary-info">Jan 21, 2022</span>
</td>
<td>
<b class="primary-info">$1,200.00</b>
<br>
<span class="converstion-option">0.00035678 BTC at $34,557.80</span>
</td>
<td>
<span class="primary-info">ACH Deposit</span>
</td>
<td class="expandable-trigger">
<a href="#">
<span class="icon icon-sm" data-icon-name="chevron-down"></span>
</a>
</td>
</tr>
<tr data-paired="4" tabindex="0">
<td>
<b class="buy-option">Bitcoin Interest Paid</b>
<br />
<span class="primary-info">Dec 15, 2021</span>
</td>
<td>
<b class="primary-info">$1,900.00</b>
<br>
<span class="converstion-option">0.00035678 BTC at $34,557.80</span>
</td>
<td>
<span class="primary-info">Interest Payment</span>
</td>
<td class="expandable-trigger">
<a href="#">
<span class="icon icon-sm" data-icon-name="chevron-down"></span>
</a>
</td>
</tr>
<tr data-paired="5" tabindex="0">
<td>
<b class="buy-option">Deposit from Chase</b>
<br />
<span class="primary-info">Dec 1, 2021</span>
</td>
<td>
<b class="primary-info">$800.00</b>
<br>
<span class="converstion-option">0.00035678 BTC at $34,557.80</span>
</td>
<td>
<span class="primary-info">Trade</span>
</td>
<td class="expandable-trigger">
<a href="#">
<span class="icon icon-sm" data-icon-name="chevron-down"></span>
</a>
</td>
</tr>
</tbody>
</table>
There are two things:
Firstly, a column when sorted is finding the class name "primary-info" to sort from that data point (vs everything) and secondly each column has different data points that can be sorted by. This doesn't seem to be working and just infinitely looping instead sorting and stopping. What am I missing here?
The problem is in this part of the code:
if(sortOrder == "desc" && x.find('.primary-info').text().replace(/[^a-zA-Z0-9 _]/g,'') < y.find('.primary-info').text().replace(/[^a-zA-Z0-9 _]/g,''))
{
shouldSwitch = true;
break;
}
else
{
shouldSwitch = true;
break;
}
This means that whatever the if condition evaluates to, it will set shouldSwitch to true and exit the inner loop. As a consequence the outer loop will keep iterating.
You should just remove the else block.
NB: it is more common practice to use the Array#sort method for sorting a table. First put rows in an array, sort it, and then populate the table again in that order.

How to deal with checkboxes in html page?

I want to get the output as single row like group name and visible or not. but in my scenario i am getting different output .
enter image description here
Here is my html code.
#model List<F3CentricMVCApp.Areas.KnowledgeBox.Models.GroupResponse>
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
<div class="col-12">
<table id="tblSectionGroups" class="table responsive table-striped" bPaginate="true">
<thead>
<tr>
<th width="95%">Groups</th>
<th width="5%" class="no-sort"></th>
</tr>
</thead>
<tbody>
#if (#ViewBag.UnAssidnedGroups is not null)
{
#foreach (var item in Model)
{
<tr>
<td>#item.Name</td>
#foreach (var unassinedGroup in ViewBag.UnAssidnedGroups)
{
#if (#unassinedGroup.GroupId == #item.Id)
{
<td>
<input type="checkbox" class="chkSectionVisibility" />
</td>
}
else
{
<td>
<input type="checkbox" class="chkSectionVisibility" checked="checked" />
</td>
}
}
</tr>
}
}
</tbody>
</table>
</div>
<script>
$('#tblSectionGroups').DataTable({
"bLengthChange": false,
"pageLength": 5,
"bPaginate": true,
"stripeClasses": [],
"info": false,
language: {
searchPlaceholder: "Type to filter list",
search: ""
},
"order": [],
"columnDefs": [{
"targets": 'no-sort',
"orderable": false,
}]
});
</script>
<div class="col-md-12 text-right">
<button type="button" class="btn btn-custom" tabindex="3" id="btnSave">Save</button>
</div>
Single checkbox for each group in a row is my requirement. any body can guide me how to deal with two collections in a code which is going through 2 foreach statements. but the logic should not be disturbed after all.
Update your foreach code as below i.e.
#if (#ViewBag.UnAssidnedGroups is not null)
{
#foreach (var item in Model)
{
int isUnassigned = 0;
<tr>
<td>#item.Name</td>
#foreach (var unassinedGroup in ViewBag.UnAssidnedGroups)
{
#if (#unassinedGroup.GroupId == #item.Id)
{
<td>
<input type="checkbox" class="chkSectionVisibility" />
</td>
// Setting.
isUnassigned++;
}
}
if (isUnassigned <= 0)
{
<td>
<input type="checkbox" class="chkSectionVisibility" checked="checked" />
</td>
}
</tr>
}
}
Hopefully this will solve your issue.

How do you add one function to work differently in different elements

I am trying to add a search function for every table in my page using jquery and ejs format. It is working when I use 2 same function with different ID. But it seems pointless and waste of time if I repeat the whole function for every table in the page. What do I need to do for this?
This is the code for search function.
$(document).ready(function(){
$('#search').keyup(function(){
search_table($(this).val());
});
function search_table(value){
$('#table_body tr').each(function(){
var found = 'false';
$(this).each(function(){
if($(this).text().toLowerCase().indexOf(value.toLowerCase()) >= 0)
{
found = 'true';
}
});
if(found == 'true')
{
$(this).show();
}
else
{
$(this).hide();
}
});
}
});
And this is the ejs code
<div class="dropdown">
<button class="button button1">Add</button>
<button class="button button2">Edit</button>
<form action="" class="search-form">
<input type="search" id="search" name="search" class="search-input" />
<i class="fa fa-search"></i>
</form>
</div>
<br />
<table class="table table-sortable" id="pagination">
<thead>
<tr>
<th>Name</th>
<th>Category</th>
<th>Description</th>
<th>Date</th>
</tr>
</thead>
<tbody id="table_body">
<% for(var i=0; i < data.employeeProfile.length; i++) { %>
<tr>
<td>
<%= data.employeeProfile[i].name %>
</td>
<td>
<%= data.employeeProfile[i].category %>
</td>
<td>
<%= data.employeeProfile[i].description %>
</td>
<td>
<%= data.employeeProfile[i].date %>
</td>
</tr>
<% } %>
</tbody>
</table>
Yes, you're right, it should be a reusable code. It's known as DRY ( Do not Repeat Yourself )
So one way of doing this is to create a function which handles the search functionality
Example :
function setSearch(inputEle, rowEle){
$(inputEle).keyup(function(){
search_table(rowEle, $(this).val());
});
}
function search_table(rowEle, value){
$(rowEle).each(function(){
var found = 'false';
$(this).each(function(){
if($(this).text().toLowerCase().indexOf(value.toLowerCase()) >= 0)
{
found = 'true';
}
});
if(found == 'true')
{
$(this).show();
}
else
{
$(this).hide();
}
});
}
Now you can set search functionality by calling setSearch for all the tables like :
setSearch('#search', '#table_body tr');
So this is the EJS code
<div class="topnav">
<img class="logo-img" src="img/cyberview.png" alt="AVATAR" />
Home
<a class="active" href="http://localhost:3000/employee">Employee</a>
Attendance
Benefit
Calendar
Medical Portal
Contracts
Feedback
Rewards
Log Out
</div>
<div class="grid-container">
<div>
<h1>Performance</h1>
<div class="dropdown">
<button class="button button1">Add</button>
<button class="button button2">Edit</button>
<form action="" class="search-form">
<input type="search" id="search" class="search-input" />
<i class="fa fa-search"></i>
</form>
</div>
<br />
<table class="table table-sortable" id="pagination">
<thead>
<tr>
<th>Name</th>
<th>Category</th>
<th>Description</th>
<th>Date</th>
</tr>
</thead>
<tbody id="table_body">
<% for(var i=0; i < data.employeeProfile.length; i++) { %>
<tr>
<td>
<%= data.employeeProfile[i].name %>
</td>
<td>
<%= data.employeeProfile[i].category %>
</td>
<td>
<%= data.employeeProfile[i].description %>
</td>
<td>
<%= data.employeeProfile[i].date %>
</td>
</tr>
<% } %>
</tbody>
</table>
</div>
</div>
<div class="grid-container">
<div>
<h1>Personal Information</h1>
<div class="dropdown">
<button class="button button1">Add</button>
<button class="button button2">Edit</button>
<form action="" class="search-form">
<input type="search" id="search" class="search-input" />
<i class="fa fa-search"></i>
</form>
</div>
<br />
<table class="table table-sortable" id="pagination2">
<thead>
<tr>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
<th>Emergency Contact</th>
<th>Joined Date</th>
</tr>
</thead>
<tbody id="table_body">
<% for(var i=0; i < data.employeeResponse.length; i++) { %>
<tr>
<td>
<%= data.employeeResponse[i].name %>
</td>
<td>
<%= data.employeeResponse[i].contact %>
</td>
<td>
<%= data.employeeResponse[i].email %>
</td>
<td>
<%= data.employeeResponse[i].emergencyContact %>
</td>
<td>
<%= data.employeeResponse[i].joinedDate %>
</td>
</tr>
<% } %>
</tbody>
</table>
</div>
</div>
And this is the code you have provided
function setSearch(inputEle, rowEle){
$(inputEle).keyup(function(){
search_table(rowEle, $(this).val());
});
}
function search_table(rowEle, value){
$(rowEle).each(function(){
var found = 'false';
$(this).each(function(){
if($(this).text().toLowerCase().indexOf(value.toLowerCase()) >= 0)
{
found = 'true';
}
});
if(found == 'true')
{
$(this).show();
}
else
{
$(this).hide();
}
});
}
setSearch('#search', '#table_body tr');

Dynamic row add/delete in Thymeleaf

I have implemented dynamic row add/delete in thymeleaf using jquery. But I am unable to capture the row values as array of json objects.
$(function(){
$('#addMore').on('click', function() {
var data = $("#tab_logic tr:eq(1)").clone(true).appendTo("#tab_logic");
data.find("input").val('');
});
$(document).on('click', '.remove', function() {
var trIndex = $(this).closest("tr").index();
if(trIndex>1) {
$(this).closest("tr").remove();
}
});
The table to which dynamic row gets added/deleted is as below:-
<table class="table table-bordered table-hover" id="tab_logic">
<tr class="tr-header">
<label for="requestno">Sales target</label>
<th>Team lead</th>
<th>Sales volume</th>
<th><a href="javascript:void(0);"
style="font-size: 18px;" id="addMore"> <span
class="glyphicon glyphicon-plus"></span></a></th>
</tr>
<tr>
<td>
<input type="text" name="teamLead" class="form-control" ></input>
</td>
<td>
<input type="text" name="salesVolume" class="form-control" ></input>
</td>
<td>
<a href='javascript:void(0);' class='remove'><span
class='glyphicon glyphicon-remove'></span></a>
</td>
</tr>
</table>
You can serialized forms inputs using the serialize() function. This will return a query string that then can be converted to JSON object using JSON.stringify(). So, my recommendation, would be to add everything inside a form and then serialize it.
HTML
<table class="table table-bordered table-hover" id="tab_logic">
<tr class="tr-header">
<label for="requestno">Sales target</label>
<th>Team lead</th>
<th>Sales volume</th>
<th><a href="javascript:void(0);"
style="font-size: 18px;" id="addMore"> <span
class="glyphicon glyphicon-plus"></span></a></th>
</tr>
<form id="myForm>
<tr>
<td>
<input type="text" name="teamLead" class="form-control" ></input>
</td>
<td>
<input type="text" name="salesVolume" class="form-control" ></input>
</td>
<td>
<a href='javascript:void(0);' class='remove'><span
class='glyphicon glyphicon-remove'></span></a>
</td>
</tr>
</form>
</table>
Javascript/jQuery
$(function(){
$('#addMore').on('click', function() {
// Add the row to your form, not the table.
var data = $("#tab_logic tr:eq(1)").clone(true).appendTo("#myForm");
data.find("input").val('');
});
$(document).on('click', '.remove', function() {
var trIndex = $(this).closest("tr").index();
if(trIndex>1) {
$(this).closest("tr").remove();
}
});
// Method that will generate the JSON object.
function toJSON() {
var data = $('#myForm').serialize();
console.log(JSON.stringify(data));
}

button doesnt work after load partialview with AJAX

i have a page that have two buttons Next and Previos. This buttons load a table in a PartialView.
My problem is when i press the button second time, it doesnt work.
Here is the code
The View :
<div id="Centros">
<div class="divPantalla2">
<table cellspacing="0" class="table table-hover table-responsive table-bordered">
<tr>
<th class="thTablas">
Nombre
</th>
<th class="thTablas">
Nro- Establecimiento
</th>
<th class="thTablas">
Departamento
</th>
<th class="thTablas">
Localidad
</th>
<th class="thTablas">
</th>
</tr>
#if (ViewBag.OnePageOfCEProyecto != null)
{
foreach (ANEP.Models.CentroEducativoModel item in ViewBag.OnePageOfCEProyecto)
{
<tr>
<td>
#item.Nombre
</td>
<td>
#item.NroEstablecimiento
</td>
<td>
#if (item.dDepartamento != null)
{
#item.dDepartamento.Descripcion;
}
</td>
<td>
#if (item.dLocalidad != null)
{
#item.dLocalidad.NomLocalidad;
}
</td>
<td>
<button type="submit" value="Eliminar+#item.CEID" name="Command" class="btn_eliminar">
</button>
</td>
</tr>
}
}
</table>
</div>
<div id="botones">
#if (ViewBag.OnePageOfCEProyecto != null)
{
<div align="center">
<div align="center">
#if (Session["PROYECTO_PAGINA_ACTUAL"] != null && int.Parse(Session["PROYECTO_PAGINA_ACTUAL"].ToString()) > 1)
{
<button type="button" id="Primera" value="Primera1" name="Command" class="btn btn-primary">
<font color="#0C58A8"><<</font></button>
<button type="button" id="Anterior" value="Anterior1" name="Command" class="btn btn-primary">
<font color="#0C58A8"><</font></button>
}
<font color="#0C58A8">#int.Parse(Session["PROYECTO_PAGINA_ACTUAL"].ToString())</font>
#if (ViewBag.OnePageOfCEProyecto.Count == 8)
{
<button type="button" id="Siguiente" value="Siguiente1" name="Command" class="btn btn-primary">
<font color="#0C58A8">></font></button>
<button type="button" id="Ultima" value="Ultima1" name="Command" class="btn btn-primary">
<font color="#0C58A8">>></font></button>
}
</div>
</div>
}
</div>
</div>
The PartialView :
<div class="divPantalla2">
<table cellspacing="0" class="table table-hover table-responsive table-bordered">
<tr>
<th class="thTablas">
Nombre
</th>
<th class="thTablas">
Nro- Establecimiento
</th>
<th class="thTablas">
Departamento
</th>
<th class="thTablas">
Localidad
</th>
<th class="thTablas">
</th>
</tr>
#if (ViewBag.OnePageOfCEProyecto != null)
{
foreach (ANEP.Models.CentroEducativoModel item in ViewBag.OnePageOfCEProyecto)
{
<tr>
<td>
#item.Nombre
</td>
<td>
#item.NroEstablecimiento
</td>
<td>
#if (item.dDepartamento != null)
{
#item.dDepartamento.Descripcion;
}
</td>
<td>
#if (item.dLocalidad != null)
{
#item.dLocalidad.NomLocalidad;
}
</td>
<td>
<button type="submit" value="Eliminar+#item.CEID" name="Command" class="btn_eliminar">
</button>
</td>
</tr>
}
}
</table>
</div>
<div id="botones">
#if (ViewBag.OnePageOfCEProyecto != null)
{
<div align="center">
<div align="center">
#if (Session["PROYECTO_PAGINA_ACTUAL"] != null && int.Parse(Session["PROYECTO_PAGINA_ACTUAL"].ToString()) > 1)
{
<button type="button" id="Primera" value="Primera1" name="Command" class="btn btn-primary">
<font color="#0C58A8"><<</font></button>
<button type="button" id="Anterior" value="Anterior1" name="Command" class="btn btn-primary">
<font color="#0C58A8"><</font></button>
}
<font color="#0C58A8">#int.Parse(Session["PROYECTO_PAGINA_ACTUAL"].ToString())</font>
#if (ViewBag.OnePageOfCEProyecto.Count == 8)
{
<button type="button" id="Siguiente" value="Siguiente1" name="Command" class="btn btn-primary">
<font color="#0C58A8">></font></button>
<button type="button" id="Ultima" value="Ultima1" name="Command" class="btn btn-primary">
<font color="#0C58A8">>></font></button>
}
</div>
</div>
}
</div>
The AJAX function (only for the button next):
$(document).ready(function () {
$("#Siguiente").on("click", function () {
var accion = $('#Siguiente').val();
$.ajax({
url: "/Proyecto/TablaCentros",
type: "GET",
cache: false,
data: { command: accion }
})
.done(function (partialViewResult) {
$("#Centros").html(partialViewResult);
});
});
});
And the controller :
public ActionResult TablaCentros(string command, Proyecto p)
{
if (command != null)
{
if (command.Contains("Siguiente1"))
{
if (Session["REGISTRO_PROYECTO"] != null)
{
Proyecto model = p;
int page = (int)Session["PROYECTO_PAGINA_ACTUAL"];
page++;
Session["PROYECTO_PAGINA_ACTUAL"] = page;
List<CentroEducativoModel> lista = (List<CentroEducativoModel>)Session["PROYECTO_CENTRO_EDUCATIVOS"];
var onePageOfCEProyecto = lista.ToPagedList(page, 8); // will only contain 15 products max because of the pageSize
ViewBag.OnePageOfCEProyecto = onePageOfCEProyecto;
cargarEstadoProyecto();
cargarCentroEducativos();
cargarClaseProyecto();
cargarTipoProyecto();
return PartialView("_TablaCentros", model);
}
}
}
return PartialView("_TablaCentros");
}
Sorry for my English,
Thanks!!!
It looks like your buttons are part of your partial view. When you initially load your view (without ajax) your button is bound to your click handler and all is well. When you click that button, your handler fires, makes the request and then replaces the #Centros content with the response -- however your bound button is part of the content that is replaced and your "new" buttons aren't bound.
You will need to rebind your handlers to your buttons after the ajax request has completed and you've loaded the result. You have a couple of options -- you can move your script to your partial view so it would fire after it's loaded, you can call your binding code in your done() handler or you can change your selector for your existing code to use a delegate.
I would use the delegate which would look similar to this:
$("#Centros").on("click", "#Siguiente", function() { ... })
This essentially means that anytime a click event happens in #Centros to an element with an ID of #Siguiente then handle the event.
I hope what ny answer will help you. What I have noticed in the signature of your Action in the controller it is supposed to receive two arguments command and Proyecto but on your ajax function you just pass command:accion So your Action does not receive the object Proyecto.