How can I add a checkbox to each row of a MVCcontrib grid. then when the form is posted find out which records were selected? I Am not finding much when searching for this. Tha
For resolving this in every get request I'm appending checked boxes value as comma separated string. Then retrieve the values from query string.
$("#pageLayout a").click(function () {
//Check for the click event insed area pageLayout
//get the href of link
var link = $(this).attr('href');
var apps = '';
//for all the checkbox get the checked status
$("input:checkbox").each(
function () {
if ($(this).attr('name') != 'IsChecked') {
if (apps != '') {
apps = apps + ',' + $(this).attr('name') + '=' + $(this).is(':checked');
}
else {
apps = $(this).attr('name') + '=' + $(this).is(':checked');
}
}
}
)
//Used to check if request has came from the paging, filter or sorting. For the filter anchor href doesnt haave
//any query string parameter. So for appending the parameter first ? mark is used followed by list of query string
//parameters.
var index = link.lastIndexOf('?');
//If there is no question mark in the string value return is -1
if (index == -1) {
//url for the filter anchor tag
//appList hold the comma sep pair of applicationcode=checked status
link = link + '?appList=' + apps + '&profileName=' + $('#ProfileName').val();
}
else {
//url for sorting and paging anchor tag
link = link + '&appList=' + apps + '&profileName=' + $('#ProfileName').val();
}
//Alter the url of link
$(this).attr('href', link);
});