How to send JQuery function value to @html.actionlink method
HI
good morning,
I need to send JQuery Method's value which is giving names of checked check boxes of the grid to do some processing.
I have a button out of the WebGrid, which is used to do some processing for the selected rows of the webgrid.
I have written jquery method which is returning names of checked check box names but I am not able to pass these name to actionlink.
In simple I am not able to call jquery method in actionlink .
Jqury method:
Code:
function GetSelectedProdcut() {
var arr = [];
var i = 0;
var str = '';
$('input:checkbox[id=chk]').each(function () {
if ($(this).is(':checked'))
str = str + $(this).val() + ",";
//arr[i++] = $(this).val();
});
$('#hid').val(str);
return str;
}
Action link :
Code:
@Html.ActionLink("Product", "DownloadZip", new { str=GetSelectedProdcut()});
Method in controller:
public void DownloadZip(string str)
{
// Here in str I need the check boxes values,
}
Thanks
Re: How to send JQuery function value to @html.actionlink method
You should assign a function call in your A tag, then change location.href to your ActionResult. Do not use void. You don't have to use an HTML helper because you don't really need your URL to go anywhere.
Code:
<a href='#' onclick='GetSelectedProdcut(); return false;'>Download Zip</a>
In your javascript function:
Code:
function GetSelectedProdcut() {
var arr = [];
var i = 0;
var str = '';
$('input:checkbox[id=chk]').each(function () {
if ($(this).is(':checked'))
str = str + $(this).val() + ",";
//arr[i++] = $(this).val();
});
location.href = '/yourcontroller/DownloadZip/?str=' + str;
return false;
}
Your DownloadZip should be an ActionResult where you will return a FILE, not a view.
Code:
public ActionResult DownloadZip(string str)
{
return File("PhysicalPathToYourFile", "application/octet-stream", "Filename.zip");
}