In the same vein as Brian Mines, you can format the url string instead of replacing -1 with your variable, that is, if I, like me, you think it's better to read. The following answer assumes that you modified the String prototype as suggested in this answer :
var url = unescape('@Url.Action("download file", "download", new { id = "{0}" })').format(myjavascriptID);
A unescape call unescape necessary if you want to decode your {0} . I like this alternative because it makes it easy to select multiple parameters from JS variables. For example:
var url = unescape('@Html.Raw(Url.Action("Action", "Controller", new { id = "{0}", name = "{1}" }))').format(myID, myName);
I added Html.Raw in my second example to avoid & in the url string.
TheWanderingMind Jul 27 '16 at 16:09 2016-07-27 16:09
source share