0

I have a problem with downloading files with Ajax.BeginForm. I know, this is not a good idea, but i really need to download using it

I have a Controller, where the file is being generated and I need to download it.

There is example, how i trying to make that:

@using (Ajax.BeginForm("GenerateFromFile", "WsdlGenerator", new AjaxOptions
        {

            HttpMethod = "Get",
            InsertionMode = InsertionMode.Replace,
            UpdateTargetId = "target",
            LoadingElementId = "loader",
            OnSuccess = "OnSuccess",
            OnBegin = "OnBegin",
            OnComplete = "OnComplite"
        }, new { enctype = "multipart/form-data", @class = "form-horizontal", role = "form" })){

    <div class="col-md-4 col-md-offset-3">
    <input id="download-button" type="submit" value="Generate" name="Generate" class="btn btn-primary btn-lg" />
                </div>
            </div>

        <div class="circleLoad" id="loader" style="display:none">
            Ваш запрос выполняется...
        </div>
        }

@section Scripts {

    <script type="text/javascript">

        function OnSuccess(response) {
        }

        function OnBegin() {
           // dowloadThisPerfectFile();
        }

        function OnComplite(url) {
        }

        pageLoad();
        //
    </script>
}

How can i download it with Ajax ? Thanks !

kxko
  • 154
  • 1
  • 10
  • 1
    If possible, you could transform the contents of the file to JSON, and then write a service to send it, which can easily be consumed in Javascript. – kkaosninja Sep 18 '16 at 16:26
  • @kkaosninja Can You show me an example ? It will be helpful for me, cuz i am beginner ) – kxko Sep 18 '16 at 16:29
  • 1
    You could read a bit about the JSON format. Its short for JavaScript Object Notation. So it's really easy to understand, and you should have no problem transforming your file to JSON, if its format is not too complex. You can start here => https://www.tutorialspoint.com/json/json_overview.htm – kkaosninja Sep 18 '16 at 16:39
  • actually i have a .zip format. So, thanks for the answer, i will read about this and i will try to make that ! Thanks )! – kxko Sep 18 '16 at 16:49

0 Answers0