We all know that to allow form to submit files, you need to specify Enctype=multipart/form-data on the form, so that you can upload files, about enctype article a lot, no longer explain.
The
problem is that the html.beginform () of MVC is used to output the form code, and the default is not to join the enctype,
Copy Code code as follows:
@using (Html.BeginForm ()) {
}
in the Partialview has a <input type= "file"/> to upload files, and do not want to this partialview to modify the parent page Html.BeginForm (), My approach is to add enctype to the form in Partialview:
Copy Code code as follows:
$ (function () {
$ (' #file '). Parents (' form '). attr (' enctype ', ' multipart/form-data ');
});
most recent mainstream browsers have been tested through no problem, but only a few older versions of IE problems, tried hand in Html.BeginForm () to add enctype can solve the problem, explain the problem in the above script. Multi-party search finally found that the title appears in ie6,7,8 does not support direct attr (' enctype ', ' multipart/form-data '), but instead sets Dom properties encoding= ' multipart/ Form-data ', the final scripting code modified to:
Copy Code code as follows:
$ (function () {
$ (' #file '). Parents (' form '). attr (' enctype ', ' multipart/form-data '). Get (0). Encoding = ' multipart/form-data ';
});