Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access javascript variable within @URL.Action()

How can I access JavaScript value inside @URL.Action()? something like:

<script type="text/javascript"> function name(myjavascriptID) {      jQuery("#list_d").jqGrid('setGridParam', { url: '@URL.Action("download file", "download", new { id = <myjavascriptID> })', page: 1 });  } </script> 
like image 240
Bolu Avatar asked Jun 23 '11 15:06

Bolu


People also ask

How to pass JavaScript variable in URL Action?

You can concat the client-side variables with the server-side url generated by this method, which is a string on the output. Try something like this: var firstname = "abc"; var username = "abcd"; location. href = '@Url.

What does URL action do?

A URL action is a hyperlink that points to a web page, file, or other web-based resource outside of Tableau. You can use URL actions to create an email or link to additional information about your data. To customize links based on your data, you can automatically enter field values as parameters in URLs.

How do I set an area in URL action?

You can use this Url. Action("actionName", "controllerName", new { Area = "areaName" });


1 Answers

You can't. JavaScript doesn't execute when generating the action URL. What you can do, is do something like this:

function name(myjavascriptID)    {      var link = '@Url.Action("download file", "download", new { id = "-1" })';      link = link.replace("-1", myjavascriptID);       jQuery("#list_d").jqGrid('setGridParam', { url: link, page: 1 }); } 
like image 125
Brian Mains Avatar answered Oct 08 '22 01:10

Brian Mains