How to Ajax Call with upload file control C# and one more parameter please see below code and help me this, I want to save an image with more than one parameter for update image. please help me achieve this.
I want to update an image with more than one parameter
$scope.myData.updateimage = function(item, event) {
var data = new FormData();
var files = $("#FileUpload1").get(0).files;
// Add the uploaded image content to the form data collection
if (files.length > 0) {
data.append("UploadedImage", files[0]);
}
$.ajax({
type: "POST",
url: "contentlist.aspx/updateid",
data: JSON.stringify({
FileUpload: data,
currentid: $scope.currentid
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
}
});
}
C# Code
[WebMethod]
public static string updateid(FileUpload FileUpload1, string currentid)
{
HttpContext context = HttpContext.Current;
string baseUrl = context.Request.Url.Authority + context.Request.ApplicationPath.TrimEnd('/');
if (FileUpload1.HasFile)
{
try
{
if (FileUpload1.PostedFile.ContentLength < 3267633)
{
string strname = FileUpload1.FileName.ToString();
string url = "http://" + baseUrl + "/Images/" + strname;
FileUpload1.PostedFile.SaveAs(url);
int id = Convert.ToInt16(appVars.updatedid);
string Query = "UPDATE SubCategories SET imageurl = WHERE id = " + id;
string result = dbAccess.ExecuteOnlyQuery(Query);
}
else
{
}
}
catch (Exception ex)
{
}
}
return "";
}