TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Kalyani Shevale
NA
3.2k
705.5k
how to pass list and Images through Ajax in MVC
Sep 19 2018 6:52 AM
I want List of data and multiple images are added in view.then this all data are passed to the Action through Ajax.how to solve this problem help me....
<
input
type
=
"file"
id
=
"file1"
name
=
"file"
multiple
/>
<button type="button" id="SubmitQuiz" class="btn btn-default" style="margin-top: 10px;"><span class="glyphicon glyphicon-ok"></span> Submit Survey </button>
jquery and ajax code
for
(
var
i = 0; i < arr.length; i++) {
resultQuiz.push({
Id: Id,
Message:
'Rating Star'
,
selectedAnswerOptionID: arr[i].starId,
value: arr[i].value,
});
}
var
fileUpload = $(
"#file1"
).get(0);
var
files = fileUpload.files;
var
fileData =
new
FormData();
var
lenimg = [];
for
(
var
i = 0; i < files.length; i++) {
lenimg.push({
names:files[i].name,
})
//fileData.append(files[i].name, files[i]);
}
debugger
;
for
(
var
j = 0; j < lenimg.length; j++)
{
resultQuiz.push({
Id: Id,
Message:
'Images'
,
selectedAnswerOptionID: lenimg[j].names,
value:
""
,
});
}
$.ajax({
type:
'POST'
,
url:
'@Url.Action("QuizTest", "Quizz")'
,
//data: fileData ,
data: { resultQuiz},
contentType:
'application/json; charset=utf-8'
,
dataType:
'json'
,
//processData: false,
//cache: false,
success:
function
(response) {
if
(response !=
null
) {
alert(
"Survey Save uccessfully."
);
}
else
{
alert(
"Survey Save uccessfully."
);
}
},
error:
function
(response) {
}
});
console.log(resultQuiz);
});
});
the Action is
public
ActionResult QuizTest(FormCollection form,List<ViewModel.Answer.Answer> resultQuiz)
{
return
view();
}
Reply
Answers (
2
)
Cookies in a shopping cart
validation in angular js mvc asp.net-validation on page load