Yva*_*van 5 javascript c# form-data asp.net-web-api
我必须在.net中的web api中检索"idPerson"的值.我已经检索了文件"UploadedImage".但我无法检索"idPerson"的值.
有人有解决方案吗?
谢谢 !
我的js功能
/**
* Upload de l'image de profil
* @method uploadFile
* @private
*/
uploadFile: function () {
var data = new FormData(), files, ajaxRequest;
files = $("#fileUpload").get(0).files;
// Ajout de l'image uploadé vers les données du form
if (files.length > 0) {
data.append("UploadedImage", files[0]);
// Ajout de l'id du patient pour calculer le GUID
data.append("idPerson", this.vm.idPerson);
}
return data;
},
Run Code Online (Sandbox Code Playgroud)
我的网页api:
/// <summary>
/// Méthode d'upload de la photo de profil du patient
/// </summary>
/// <returns>Etat du téléchargement de l'image</returns>
public MessageOutCoreVm UploadImg()
{
string fileSavePath = string.Empty;
string virtualDirectoryImg = "UploadedFiles";
string fileName = string.Empty;
if (HttpContext.Current.Request.Files.AllKeys.Any())
{
// Get the uploaded image from the Files collection
var httpPostedFile = HttpContext.Current.Request.Files["UploadedImage"];
fileName = httpPostedFile.FileName;
if (httpPostedFile != null)
{
// OBtient le path du fichier
fileSavePath = Path.Combine(HttpContext.Current.Server.MapPath("~/UploadedFiles"), httpPostedFile.FileName);
// Sauvegarde du fichier dans UploadedFiles sur le serveur
httpPostedFile.SaveAs(fileSavePath);
}
return MessageOutCoreVm.SendSucces(virtualDirectoryImg + '/' + fileName);
}
else
{
return MessageOutCoreVm.SendValidationFailed("");
}
}
Run Code Online (Sandbox Code Playgroud)
kam*_*lod 12
假设您正在发送典型的Ajax POST请求,您可以从HttpContext.Current.Request.Form集合中检索每个字段.
只需在集合中找到您的密钥即可 HttpContext.Current.Request.Form["KEY"]
当您没有提供发送数据的方式时,很难说如何检索任何值.
| 归档时间: |
|
| 查看次数: |
11660 次 |
| 最近记录: |