jquery - How to add parameters to a @Url.Action() call from JavaScript on click -


I have a link when it needs to call a controller action with some data, which is via JavaScript The operation must be recovering from a filestream resilient returning.

I looked at @ Url.Action but I could not understand how (or even) I could pass value dictionary material that could be recovered through JS.

Then I came from a click handler with a $ .post. The problem I am facing is that I'm not sure what to do in my success: function () user streams the file To return the results. Or even if I can do too.

Then you will do something like this but someone will be helpful ..

Then I went from a click handler with a $ .post. The problem I am facing is that I am not sure what to do in my success: function () to return the file stream result to the user . Or can I still do

You can not do much with a received byte in JavaScript: obviously you can not save it on the client computer nor can it pass it on to the client in some external program Are there. So do not call activities that AJAX wants to return files to. For those tasks, you should use the normal link:

  @ Html.ActionLink ("download file", "download", new {id = 123})   

and let the user decide what to do with the file. You can play with the content-breaker header and set it to either inline or attachment , depending on whether If you want to open the file, indicate the default affiliate program inside the browser or with the user save file dialog.


Update:

It seems that I misunderstood this question if you want to add parameters to an existing link, then you can subscribe to javascript click event And modify the query by adding the required parameters in the string:

  $ (function () {$ ('# mylink'). (Function () {var someValue = 'Value of parameter'; $ (this) .attr ('href', this.href + 'nickname =' + encodeuric component (some value); return true;});});    

Comments