0
我上传MP4到我的MVC控制器,但阿贾克斯返回此错误:“错误错误未找到未定义” 我的观点上传MP4到MVC控制器故障
<form id="CrearRecurso">
<div class="container">
<div class="form-group">
@Html.LabelFor(m => m.Imagen)
@Html.TextBoxFor(m => m.Imagen, new { type = "file", name = "Imagen" })
@Html.ValidationMessageFor(m => m.Imagen)
</div>
<button id="submiter" type="submit" class="btn btn-primary">Crear recurso!</button>
</div>
这是我的ajax部分,我称之为我的API。但是我收到了一个错误,你会在代码后面看到下面的错误。
$('#CrearRecurso').submit(function (e) {
var formData = new FormData($('#CrearRecurso').get(0));
jQuery.support.cors = true;
var files = $("#Imagen").get(0).files;
var name = files.name;
if (files.length > 0) { //checks if there is a file
if (window.FormData !== undefined) {
$.ajax({
type: "post",
url: '/api/mycontroller/Create?MyId=' + LeccionId,
contentType: false,
processData: false,
data: formData,
success: function (result) {
//do something
},
error: function (ts) { alert(ts.responseText) }
});
}
}
}
});
});
当我上传PDF或JPG它是好的,但是当我使用的MP4文件,我在警报得到这个错误。
相关文件上传的模型如下:
[Required]
[DataType(DataType.Upload)]
public HttpPostedFileBase Imagen { get; set; }
为什么会发生呢?谢谢。
更新1:我的文件大小约为50mb。它可能与问题有关吗?
因为一开始你不取消默认的提交,所以你做一个GET来生成视图的方法,再加上你的Ajax调用 –
''/ API/myController的/创建? MyId ='+ LeccionId' =>你的错误不会触及那个动作方法,那是'LeccionId' null还是空的?弹出窗口会显示,因为您的AJAX调用返回错误响应并触发'alert(ts.responseText)'。 –
Tetsuya,实际上当我使用pdf或jpg时,它调用api时没有任何问题,但对于mp4,我得到该错误 –