How to receive Open/Save file dialog after ajax-form post with ASP.NET MVC and jQuery -


i want able receive open/save dialog pdf file being returned controller without using 'html.beginform' in asp.net mvc. i´m using 'ajax.beginform' since can register events fire onbegin , oncomplete (which think can´t when using html.beginform, or it?).

i want state problem not creating , receiving file server when using 'html.beginform' because works fine, without events want use. i´m using 'ajax.beginform' , file being returned controller nothing happens after client side.

my cshtml

@using (ajax.beginform("createpdf", "print", null, new ajaxoptions() { loadingelementid = "printloading", onsuccess = "printpagecomplete"}, new { id = "exportform" })) {     //stuff abbreviated     <input type="button" onclick="onprint()" /> } 

my jquery

function onprint() {     //stuff abbreviated     $("#exportform").submit(); }  function printpagecomplete(result) {     //this 'result' variable holding file controller      //stuff abbreviated      //todo: need open file dialog here } 

my controller

[httppost] public actionresult createpdf(formcollection collection) {     //stuff abbreviated     return file(thepdf, _mimetypes[exportformat.pdf], "thepdf.pdf") } 

as can see i´ve managed far in printpagecomplete function i´m not sure go here. should continue using ajax form or should stick html form , try find other way fire events sorely need use?

perhaps i´m going wrong , appreciated.

you can post form without using ajax.beginform. more work, gives more flexibility:

$('#exportform').submit(function (e){    e.preventdefault();    //do validation or custom    $.ajax({      //set ajax settings       success: function(){        // handle success event      }     }); }); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -