jquery - @Html.ActionLink adding class and id -


trying add class action link , id value, capture class , pass value controller.

i have jquery capture link click:

<script> $(function () {     $(".actionlink").click(function (e) {         e.preventdefault();         var newurl = $(this).attr("href");                     console.log(newurl);         $("#addsection").load(newurl);                 }); }); 

tried few different ways without success.

first 1 is

@html.actionlink("edit", "_editgender1", new { id = item.genderid }) 

which returns html: <a href="/treeview/_editgender1/1">edit</a>

obviously 1 won't work assigned id correctly end of url /1

second one:

@html.actionlink("edit", "_editgender1", new { @class = "addsection", id = item.genderid }) 

which returns: <a href="/treeview/_editgender1/1?class=addsection">edit</a>

the id again added correctly, though has class=addsection jquery not capture this.

 @html.actionlink("edit", "_editgender1", "treeview", null, new { @class = "addsection", id = item.genderid })   

returns: <a class="addsection" href="/treeview/_editgender1" id="1">edit</a>

this captured jquery correctly, isn't passing id url , controller.

not sure else try!

@html.actionlink has overload add route values , html attributes.

@html.actionlink("edit", "_editgender1", new { id = item.genderid }, new { @class = "addsection" }) 

the 3rd parameter adds route values , 4th parameter adds html attributes.

refer documentation


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -