Home Web Front-end JS Tutorial Problem with dynamically inserting enctype=multipart/form-data on form using js_form effects

Problem with dynamically inserting enctype=multipart/form-data on form using js_form effects

May 16, 2016 pm 05:53 PM
form form-data multipart

We all know that in order for the form to be able to submit files, we need to specify the attribute enctype=multipart/form-data on the form so that files can be uploaded. There are many articles about enctype, so I won’t explain it here.

The problem is that MVC's Html.BeginForm() is used to output the form code. Enctype is not added by default.

Copy code The code is as follows:

@using (Html.BeginForm()) {
}

There is a < in PartialView ;input type="file" /> is used to upload files, but I don’t want to modify the Html.BeginForm() of the parent page for this PartialView. My approach is to use a script in PartialView to add enctype to the form:

Copy code The code is as follows:

$(function(){
$('# file').parents('form').attr('enctype', 'multipart/form-data');
});

Have the recent mainstream browsers passed the test? Problem, only a few old versions of IE have problems. I tried manually adding enctype to Html.BeginForm() to solve the problem, which means that the problem lies in the above script. After multiple searches, I finally found that the problem occurs because IE6, 7, and 8 do not support direct attr('enctype', 'multipart/form-data'), but set the dom attribute encoding='multipart/form-data', and the final script code Modify to:

Copy code The code is as follows:

$(function () {
$('#file').parents('form').attr('enctype', 'multipart/form-data').get(0).encoding = 'multipart/form-data';
});
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use SpringBoot framework to receive multipart/form-data files How to use SpringBoot framework to receive multipart/form-data files May 16, 2023 pm 03:31 PM

The SpringBoot framework receives multipart/form-data files. Now many file upload types are of the multipart/form-data type. The HTTP request is as follows: But the problem is that if you use traditional Struts2 or servlet, you can easily receive files. Function, for example, the following code can be implemented: booleanisMultipart=ServletFileUpload.isMultipartContent(request);//Determine whether it is a form file type DiskFileItemFactoryfactory=newD

How to use form-data to upload file requests in Python How to use form-data to upload file requests in Python May 15, 2023 am 09:10 AM

Although most of the conventional interfaces are now requested in json form, it is inevitable that some interfaces need to transmit file streams. At this time, you need to upload for.e in form-data form: The following interfaces exist. Creating poster images through the interfaces requires Upload thumbnails. At this time, the Content-Type of the interface cannot be application/json, but multipart/form-data; the parameter format is also passed into postman in the form of a form. Setting the file stream is very simple. Set the file format, and then you can Select the file to upload locally. See the actual request interface in the figure below. You can successfully use python to complete the above request. You need to specify the request method and data type.

BinaryX is renamed FORM again, and the FOUR it gives to the community is about to soar? BinaryX is renamed FORM again, and the FOUR it gives to the community is about to soar? Mar 04, 2025 pm 12:00 PM

BinaryX's token name change: from BNX to FOUR, and then to FORM, the deep meaning behind strategic adjustments BinaryX recently changed the token symbol from $FOUR to $FORM, which has attracted widespread attention from the industry. This is not the first time BinaryX has changed its name, and its token symbol has undergone a transition from BNX to FOUR. This article will explore in-depth the strategic intentions behind this series of name change. 1. Token name change process and strategic considerations BinaryX initially launched the $BNX token based on the BNB chain in 2021 to support its Play-to-Earn (P2E) gaming ecosystem. In early 2024, in order to optimize the economic model, BinaryX divided $BNX and gradually expanded to GameF

Can there be multiple forms in html5? Can there be multiple forms in html5? Aug 01, 2022 pm 05:28 PM

There can be multiple forms in html5. The rules allow multiple form tags to be used in the same HTML page. However, in order to prevent the backend from not recognizing it when submitting, you need to add different IDs or classes to the form. The syntax is "<from action="url" id=" id value 1">Form element</from><from action="url" id="id value 2">Form element</from>.....".

What is the tag that defines the form in html5 What is the tag that defines the form in html5 Jul 26, 2022 pm 04:26 PM

The tag defining a form in HTML5 is "<form>". The form tag is used to create an HTML form (form field) for user input to collect and transfer user information. All content in the form will be submitted to the server; the syntax "<form action="Submit Address" method="Submit Method " name="form name">form control</form>". A form can contain one or more form elements, such as input, select, and textarea.

Comprehensively organize elements related to form forms! Comprehensively organize elements related to form forms! Aug 05, 2022 am 11:45 AM

This article gives you a detailed summary of the knowledge points related to form elements in HTML. I hope it will be helpful to you!

php记录搜索引擎蜘蛛爬行记录代码 php记录搜索引擎蜘蛛爬行记录代码 Jun 13, 2016 am 10:08 AM

php记录搜索引擎蜘蛛爬行记录代码。php教程记录搜索引擎蜘蛛爬行记录代码 center form action=setup.php method=post table align=center tr td服务器:/tdtdinput value=localhost name=server //td /tr tr td用

What should I do if the form cannot be submitted to php? What should I do if the form cannot be submitted to php? Dec 01, 2022 am 09:08 AM

Solution to form form cannot be submitted to PHP: 1. Open the corresponding code file; 2. Modify the "onload="javascript:document.form1.submit();" statement; 3. Change the name of submit.

See all articles