asp.net mvc - embedding javascript variable within razor syntax -
i have method looks this
function endcall_click(leadid) { document.location = '@url.action("index","dispo",new{id=leadid})/'; }
of course doesn't work because treats "leadid" server side variable want inject javascript variable passed method.
i tried wrapping lead id in didn't work.
function endcall_click(leadid) { document.location = '@url.action("index","dispo",new{id="<text>leadid</text>"})/'; }
any ideas?
you can't inject javascript variable script evaluated @ server because @ moment script executes , generates output variable hasn't yet come existence. way achieve manipulate resulting string:
function endcall_click(leadid) { document.location = '@url.action("index", "dispo")/' + leadid; }
the drawback assumes manipulating routes in javascript , if decide change them on server code might break.
Comments
Post a Comment