I am trying to pass strings array to my mvc action but I am getting Null value.
This is my javascript/Jquery
var array = ["Good Morning", "Good Afternoon", "Good Evening"]
var postData= { imageList: array };
$('button').on('click', function () {
$.ajax({
url: "/Home/Greetings",
type: 'POST',
data: postData,
dataType: "json",
traditional: true,
success: function (data) {
array = [];
},
error: function (xhr, status, err) {
}
});
});
My Code in Asp.net MVC is
[HttpPost]
public string Greetings(List postData)
{
string result = "";
foreach(var item in postData)
{
result += item + " ";
}
return result;
}
Ramesh PalanivelPosted Feb 18, 2018, 11:08 PM
Istudent RanaPosted Feb 19, 2018, 8:45 AM
{
static List
{
"1615\\1211\\0\\mustang.jpg",
"1615\\1211\\0\\audi.jpg",
"1615\\1211\\0\\bmw.jpg"
};
public ActionResult Index()
{
DownLoadZip(ingList);
return View();
}
{
string imgFile = "";
string imgKey = "";
if (imgList.Count > 0)
{
string[] fileNames = imgList.FirstOrDefault().ToString().ToLower().Split('\\');
string fileName = "DaysImage_";
fileName += fileNames[0] + fileNames[1] + fileNames[2] + ".zip";
{
{
imgKey = imgPath.Substring(imgPath.LastIndexOf("\\") + 1);
imgFile = imgRootPath + imgPath;
zipFile.AddEntry(imgKey, imgFile);
}
Response.ClearHeaders();
Response.AppendHeader("content-disposition", "attachment; filename=" + fileName );
}
}
}
Istudent RanaPosted Feb 19, 2018, 8:28 AM
Ramesh PalanivelPosted Feb 19, 2018, 8:27 AM
Dharmraj ThakurPosted Feb 19, 2018, 8:16 AM
Mangesh GPosted Feb 19, 2018, 8:14 AM
Istudent RanaPosted Feb 19, 2018, 7:57 AM
Istudent RanaPosted Feb 19, 2018, 7:54 AM
// var imagename = imageID.substring(2);
// var image = "";
// if (typeof newimagename != "undefined") {
// if (newimagename.length != 0) {
// image = newimagename;
// }
// else {
// image = imagename;
// }
// }
// else {
// image = imagename;
// }
// var day = $("#questionlist").attr("data-day");
// var StoreNumber = $("#questionlist").attr("data-StoreNumber");
// var ProjectID = $("#questionlist").attr("data-ProjectID");
// var name = image.replace(/\./g, '\\.');
// imagename = imagename.replace(/\./g, '\\.');
// if (jpg == -1) {
// image = image + ".jpg";
// }
imgSourcePathCollection = ["1615\\1211\\0\\audi.jpg", "1615\\1211\\0\\bmw.jpg", "1615\\1211\\0\\mustang.jpg"]
url: "/Home/DownloadImages",
headers: { "__RequestVerificationToken": token },
type: 'POST',
data: JSON.stringify(postData),
dataType: "json",
traditional: true,
success: function (data) {
imgSourcePathCollection = [];
},
[HttpPost]
public void DownloadImages(List
{
try
{
string imgRootPath = ConfigurationManager.AppSettings["filepath"] + "\\";
string imgKey = string.Empty;
{
string[] fileNames = postData.FirstOrDefault().ToString().ToLower().Split('\\');
string fileName = "DaysImage_";
fileName += fileNames[0] + fileNames[1] + fileNames[2] + ".zip";
{
foreach (var imgPath in postData)
{
imgKey = imgPath.Substring(imgPath.LastIndexOf("\\") + 1);
imgFile = imgRootPath + imgPath;
zipFile.AddEntry(imgKey, imgFile);
}
Response.ClearHeaders();
Response.AppendHeader("content-disposition", "attachment; filename=" + fileName);
}
}
catch (Exception ex)
{
string s = ex.ToString();
}
}
Dharmraj ThakurPosted Feb 19, 2018, 7:51 AM
Istudent RanaPosted Feb 19, 2018, 7:40 AM
SyntaxError: Unexpected end of JSON input
at parse (
Istudent RanaPosted Feb 19, 2018, 7:30 AM
I tried the way you asked me, I got below error:
Unexpected token P in JSON at position 0
Dharmraj ThakurPosted Feb 18, 2018, 11:30 PM