Friday, May 10, 2024
Homepage · c#
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  13] [ 4]  / answers: 1 / hits: 24098  / 9 Years ago, thu, may 7, 2015, 12:00:00

I have to retrieve the value of idPerson in my web api in .net.
I already retrieve the file UploadedImage. But I can't retrieve the value of idPerson.



Someone have a solution?



Thx !



my js function



        /**
* 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;
},


my web 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();
}
}

More From » c#

 Answers
17

Assuming your are sending typical Ajax POST request, you can retrieve each field from HttpContext.Current.Request.Form collection.



Just find your key in collection like HttpContext.Current.Request.Form[KEY]



TBH it is hard to say how to retrieve any value when you did not provide the way of sending data.


[#66699] Tuesday, May 5, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emerymariamm

Total Points: 276
Total Questions: 97
Total Answers: 99

Location: Comoros
Member since Sun, Dec 13, 2020
3 Years ago
;