jquery - Embed Html.ActionLink in Javascript in Razor -
i know it's possible embed @html in javascript in mvc3, can't following work , not sure if possible yet.
using jquery datatable, have ajax call create new row, programatically add using datatable api. works, want put edit actionlink onto row , shows text "edit", not link.
of course manually, wondering if there better option.
e.g.
tablepallets.fnadddata([ getpalletactionlinks(), etc... function getpalletactionlinks() { var result = @html.actionlink("edit", "editpallet", new { id = 1 }); return result; }
i've hard coded id = 1 moment, can newly created row.
thanks duncan
i think it's simple adding quotes around link:
var result = '@html.actionlink("edit", "editpallet", new { id = 1 })';
this generate whole <a>
tag. return url:
var result = '@url.action("editpallet", new { id = 1 })';
and embed in existing anchor using jquery:
<!-- let's imagine exists --> <a href="#" id="dynamiclink">edit</a> // result ovbiously other function returns $("#dynamiclink").attr("href", result);
Comments
Post a Comment