我想在我的网站上使用此 jQuery 文件上传 https://github.com/blueimp/jQuery-File-Upload根据文档,我需要创建自己的文件上传处理程序,我想知道是否有人有在 webmatrix 站点中使用 jQuery 文件上传的经验?
而且,我找不到创建自己的文件上传处理程序所需的信息。如果有人可以提供帮助,那就太好了。
最佳答案
我可以帮助你,我为我创建的网站创建了一个文件(图像) uploader 。
CSHTML 部分 (sube_archivos.cshtml):
@{
if (IsPost)
{
var fileName = Path.GetFileName(Request.Files["archivo"].FileName);
var fileSavePath = Server.MapPath("~/Temp/" + fileName);
try
{
Request.Files["archivo"].SaveAs(fileSavePath);
<img src="~/Temp/@fileName" /> @*you could comment this line...it was the succesful response...an image preview*@
}
catch (Exception)
{
<text>Error en la subida del archivo</text> @*you could comment this line...error in the uploading*@
}
}
}
JQUERY/JAVASCRIPT 部分:
function sube(archivo) {
var primer_archivo = archivo.files[0];
var data = new FormData();
data.append('archivo', primer_archivo);
$.ajax({
url: "@Href("../../operaciones/sube_archivos.cshtml")",
type: "POST",
contentType: false,
data: data,
processData: false,
cache: false,
success: function (response) {
//here I put the response ....the image preview or the error message
$(archivo).parent().next('.imagen_cargada').html(response);
//here I get the file name and I add it to some specific div
$(archivo).parent().next().next('.nombre_imagen').val($(archivo).val().split('\\').pop());
}
});
}
HTML 部分:
<form method="post" enctype="multipart/form-data">
<input type="file" name="archivo" onchange="sube(this)" />
</form>
祝你好运,如果有任何不清楚的地方请告诉我。
关于jquery - 如何在 webmatrix(ASP.NET 网页)中使用 jQuery 文件上传?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16072762/