javascript - pass file as parameter using jquery in asp .net mvc -


in order import data file excel , display data in ascx page, want pass file parameter controller via jquery function here code: view:

<% using (html.beginform (new {enctype = "multipart / form-data"}))                      {%>                          <input type = "file" name = "file" />                          <input type = "button" value = "ok" onclick = "import (); return false;" />                      <%}%> 

jquery:

import function () {      var formdata = new formdata ();      formdata = file      var dialog = new messagebox ();      $ .ajax ({          type: 'post'          url: "/ controller / import"          data: formdata,          cache: false,          contenttype: false,          processdata: false,          success: function (view) {              alert ("success");              $ ("# divlist"). empty ()              $ ("# mainpagemaincontent") append (view).;          },          complete: function () {              closepatienter ();              dialog.msgclose ();          }      }); } 

controller:

public actionresult import(httppostedfilebase file) {       ......       return partialview("otherview", model); } 

when execute this, file in controller null can me thank in advance

you not adding file formdata obj. this:

var formdata = new formdata (); //formdata = file var uploadfield = document.getelementbyid('uploadfield'); formdata.append("file", uploadfield.files[0]); 

where "uploadfield" id of file input element.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -