1

Topic: File loading on button click

Hello.
It is impossible to load a file from the server on button click. Now there is button "Generate" on page. On pushing it there is a link generation on page. Then the user can load a file on pushing the link. But it is superfluous cliques. It would be desirable to send the given forms and to load a file at once on a clique on button "Generate".
The controler code:

public ActionResult GeneratorDetails (GeneratorDetailsModel model)
{
//display of a page of generation
return PartialView ("GeneratorDetailsContent", model);
}
public FileStreamResult GeneratorFiles (GeneratorDetailsModel model)
{
//request of a file
return File (model. File, "text/plain", "file.txt");
}

In page:

<form>
...
<input type = "submit" value = "Generate"/>
@{
if (this. Model. FilesReady)
{
@Html. ActionLink ("Download", "GeneratorFiles", "GeneratorDetails", new {filename = "file.txt"})
}
}
</form>

Tried such variant - does not work:

<a href = "/GeneratorDetails/GeneratorFiles" download>
<button type = "submit"> Generate </button>
</a>

Prompt please as it to implement?

2

Re: File loading on button click

While found such decision... Not so it is pleasant, but works.

<form id = "mainForm"...>
...
<input type = "submit" value = "Generate"/>
@Html. ActionLink ("Download", "GeneratorFiles", "GeneratorDetails", new {filename = "file.zip", id = "FileLink", @class = "hidden"})
</form>
<script...>
var form = $ ("#mainForm");
var link = form.find (' #FileLink ');
link [0].click ();
</script>

I do the latent link and after form reset I click with its script.