无法读取上传的文件。 [英] Not able to read uploaded file.
本文介绍了无法读取上传的文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
点击任意图片,我需要上传所选的新文件。但是我的脚本出错了
var file1 = $(this).file [0];
我的观点:
@using(@ Html.BeginForm(uploadProductImage ,SellereLogin,FormMethod.Post,new {enctype =multipart / form-data}))
{
< table id =listOfProduct>
< tr>
< th>
@ Html.DisplayNameFor(model => model.ProductId)
< / th>
< th>
@ Html.DisplayNameFor(model => model.Image1Id)
< / th>
< th>
@ Html.DisplayNameFor(model => model.Image2Id)
< / th>
< th>
@ Html.DisplayNameFor(model => model.Image3Id)
< / th>
< th>
@ Html.DisplayNameFor(model => model.Image4Id)
< / th>
< th>< / th>
< / tr>
@foreach(模型中的var项目)
{
< tr>
< td>
@ Html.DisplayFor(modelItem => item.ProductId)
< / td>
< td>
@ Html.HiddenFor(m => item.Image1Id)
< img src =@ System.Configuration.ConfigurationManager.AppSettings [prodImage]class =click />
< / td>
< td>
@ Html.HiddenFor(m => item.Image2Id)
< img src =@ System.Configuration.ConfigurationManager.AppSettings [prodImage]class =click />
< / td>
< td>
@ Html.HiddenFor(m => item.Image3Id)
< img src =@ System.Configuration.ConfigurationManager.AppSettings [prodImage]class =click />
< / td>
< td>
@ Html.HiddenFor(m => item.Image4Id)
< img src =@ System.Configuration.ConfigurationManager.AppSettings [prodImage]class =click />
@ * @ Html.ActionLink(更改,uploadProductImage,新{productId = item.ProductId,imageId = item.Image4Id})* @
< / td>
< / tr>
}
< / table>
< div>
< input type =fileid =file1style =display:none/>
< / div>
}
我的剧本:
<脚本>
$(function(){
$('。click')。on('click',function(){
$('#file1')。trigger('click') ;
});
$('#file1')。on('change',function(){
debugger;
var file1 = $(this ).file [0];
var formData = new FormData($('form')[0]);
$ .ajax({
type:POST ,
url:SellereLogin / uploadProductImage,
enctype:'multipart / form-data',
data:{
file:file1,
productId:123,
imageId:12345
},
成功:function(){
alert(数据上传:);
}
});
});
});
< / script>
解决方案
(this).file [0];
我的观点:
@using(@ Html.BeginForm(uploadProductImage,SellereLogin) ,FormMethod.Post,new {enctype =multipart / form-data}))
{
< table id =listOfProduct>
< tr>
< th>
@ Html.DisplayNameFor(model => model.ProductId)
< / th>
< th>
@ Html.DisplayNameFor(model => model.Image1Id)
< / th>
< th>
@ Html.DisplayNameFor(model => model.Image2Id)
< / th>
< th>
@ Html.DisplayNameFor(model => model.Image3Id)
< / th>
< th>
@ Html.DisplayNameFor(model => model.Image4Id)
< / th>
< th>< / th>
< / tr>
@foreach(模型中的var项目)
{
< tr>
< td>
@ Html.DisplayFor(modelItem => item.ProductId)
< / td>
< td>
@ Html.HiddenFor(m => item.Image1Id)
< img src =@ System.Configuration.ConfigurationManager.AppSettings [prodImage]class =click />
< / td>
< td>
@ Html.HiddenFor(m => item.Image2Id)
< img src =@ System.Configuration.ConfigurationManager.AppSettings [prodImage]class =click />
< / td>
< td>
@ Html.HiddenFor(m => item.Image3Id)
< img src =@ System.Configuration.ConfigurationManager.AppSettings [prodImage]class =click />
< / td>
< td>
@ Html.HiddenFor(m => item.Image4Id)
< img src =@ System.Configuration.ConfigurationManager.AppSettings [prodImage]class =click />
@ * @ Html.ActionLink(更改,uploadProductImage,新{productId = item.ProductId,imageId = item.Image4Id})* @
< / td>
< / tr>
}
< / table>
< div>
< input type =fileid =file1style =display:none/>
< / div>
}
我的剧本:
< script>
(function(){
('。click')。on('click',function() {
On click of any Image I need to upload the new file selected. But I get error in my script
var file1 = $(this).file[0];
My View :
@using (@Html.BeginForm("uploadProductImage", "SellereLogin", FormMethod.Post, new { enctype = "multipart/form-data" })) { <table id="listOfProduct"> <tr> <th> @Html.DisplayNameFor(model => model.ProductId) </th> <th> @Html.DisplayNameFor(model => model.Image1Id) </th> <th> @Html.DisplayNameFor(model => model.Image2Id) </th> <th> @Html.DisplayNameFor(model => model.Image3Id) </th> <th> @Html.DisplayNameFor(model => model.Image4Id) </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.ProductId) </td> <td> @Html.HiddenFor(m => item.Image1Id) <img src ="@System.Configuration.ConfigurationManager.AppSettings["prodImage"]" class="click"/> </td> <td> @Html.HiddenFor(m => item.Image2Id) <img src ="@System.Configuration.ConfigurationManager.AppSettings["prodImage"]" class="click"/> </td> <td> @Html.HiddenFor(m => item.Image3Id) <img src ="@System.Configuration.ConfigurationManager.AppSettings["prodImage"]" class="click"/> </td> <td> @Html.HiddenFor(m => item.Image4Id) <img src ="@System.Configuration.ConfigurationManager.AppSettings["prodImage"]" class="click"/> @*@Html.ActionLink("Change", "uploadProductImage", new { productId = item.ProductId, imageId = item.Image4Id })*@ </td> </tr> } </table> <div> <input type="file" id="file1" style="display: none" /> </div> }
My Script :
<script> $(function () { $('.click').on('click', function () { $('#file1').trigger('click'); }); $('#file1').on('change', function () { debugger; var file1 = $(this).file[0]; var formData = new FormData($('form')[0]); $.ajax({ type: "POST", url: "SellereLogin/uploadProductImage", enctype: 'multipart/form-data', data: { file: file1, productId: 123, imageId: 12345 }, success: function () { alert("Data Uploaded: "); } }); }); }); </script>
解决方案
(this).file[0];
My View :
@using (@Html.BeginForm("uploadProductImage", "SellereLogin", FormMethod.Post, new { enctype = "multipart/form-data" })) { <table id="listOfProduct"> <tr> <th> @Html.DisplayNameFor(model => model.ProductId) </th> <th> @Html.DisplayNameFor(model => model.Image1Id) </th> <th> @Html.DisplayNameFor(model => model.Image2Id) </th> <th> @Html.DisplayNameFor(model => model.Image3Id) </th> <th> @Html.DisplayNameFor(model => model.Image4Id) </th> <th></th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.ProductId) </td> <td> @Html.HiddenFor(m => item.Image1Id) <img src ="@System.Configuration.ConfigurationManager.AppSettings["prodImage"]" class="click"/> </td> <td> @Html.HiddenFor(m => item.Image2Id) <img src ="@System.Configuration.ConfigurationManager.AppSettings["prodImage"]" class="click"/> </td> <td> @Html.HiddenFor(m => item.Image3Id) <img src ="@System.Configuration.ConfigurationManager.AppSettings["prodImage"]" class="click"/> </td> <td> @Html.HiddenFor(m => item.Image4Id) <img src ="@System.Configuration.ConfigurationManager.AppSettings["prodImage"]" class="click"/> @*@Html.ActionLink("Change", "uploadProductImage", new { productId = item.ProductId, imageId = item.Image4Id })*@ </td> </tr> } </table> <div> <input type="file" id="file1" style="display: none" /> </div> }
My Script :
<script>
(function () {
('.click').on('click', function () {
这篇关于无法读取上传的文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文