pass actionlink parameters to jquery function

0

How do I pass parameters from an ActionLink from a grid to a jquery function?

This is ActionLink:

 gridPortfolio.Column( format: @<text> @Html.ActionLink("Delete", "DeleteData", new {id = item.CD_PORTFOLIO, par = "PO"}, new { @onClick =  "deleteData()", @class="ActionImgD" })</text>)

and this is the function:

function deleteData(params) {//conteudo}
    
asked by anonymous 23.06.2015 / 15:47

1 answer

1

You can concatenate the parameters at the time of creating ActionLink .

@Html.ActionLink("Delete", "DeleteData", 
                 new {id = item.CD_PORTFOLIO, par = "PO"}, 
                 new { onclick = "return deleteData('" + item.CD_PORTFOLIO + "', 'PO');", @class="ActionImgD" })


Another option is to use the data-* attributes.

@Html.ActionLink("Delete", "DeleteData", 
                 new {id = item.CD_PORTFOLIO, par = "PO"}, 
                 new { onclick = "return deleteData();", 
                       @class="ActionImgD",
                       data_cd = item.CD_PORTFOLIO  /* isso aqui */
                     })

That will generate a data-cd="seuvalor" attribute in the tag. To recover:

function deleteData() {
    var cd = $(this).data('cd');
    //...
}
    
23.06.2015 / 16:05