JS dynamic insert on Form enctype=multipart/form-data problem _ form Effects

Source: Internet
Author: User
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.

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 ';

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.