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
Shoaib Ahmed
NA
189
5.3k
Passing different lists of data to view from controller
Jan 11 2019 4:02 PM
First, I am getting data in parsedArray below,
JArray parsedArray = JArray.Parse(stringData);
I have a user defined type list named QuestionAnsweList. Now, For each parsedproperty I have initialized parsedproperty.name as my question and parsedproperty.value as my answer. I want to send Note with question answer whenever I find "/" in the question else send only question and answer in a list. Also, I want to send same Note question answer to be sent together so that I can print them together in view.
List<QuestionAnswer> QuestionAnswerList =
new
List<QuestionAnswer>();
foreach
(JObject parsedObject
in
parsedArray.Children<JObject>())
{
foreach
(JProperty parsedProperty
in
parsedObject.Properties())
{
string
Question = parsedProperty.Name.ToString();
//string Answer = Convert.ToString(parsedProperty.Value);
if
(Question.Contains(
"/"
))
{
string
[] Notes = Question.Split(
'/'
);
QuestionAnswer aNoteQuestionAnswer =
new
QuestionAnswer();
aNoteQuestionAnswer.Note = Notes[0].ToString();
aNoteQuestionAnswer.Question = Notes[1];
aNoteQuestionAnswer.Answer = Convert.ToString(parsedProperty.Value);
QuestionAnswerList.Add(aNoteQuestionAnswer);
}
else
{
QuestionAnswer aQuestionAnswer =
new
QuestionAnswer();
aQuestionAnswer.Question = Question;
aQuestionAnswer.Answer = Convert.ToString(parsedProperty.Value);
QuestionAnswerList.Add(aQuestionAnswer);
}
}
}
return
View(QuestionAnswerList);
}
QuestionAnswer Class :
public
class
QuestionAnswer
{
public
string
Note {
get
;
set
; }
public
string
Question {
get
;
set
; }
public
string
Answer {
get
;
set
; }
}
My View :
@model IEnumerable<EnracProject.Models.QuestionAnswer>
<table
class
=
"table table-bordered"
>
@foreach (
var
QuestionAnswers
in
Model)
{
<tr>
<td>@QuestionAnswers.Serial</td>
</tr>
<tr>
<td>@QuestionAnswers.Note</td>
</tr>
<tr>
<td>Question : @QuestionAnswers.Question</td>
<td>Answer : @QuestionAnswers.Answer</td>
</tr>
}
</table>
In the table, I want Question and Answers to print in a trow tag. but Whenever a "/" question found in the controller I want to bind all those questions and answers print them here like In a row note then question answer . There can be many questions answers under same name note.
How can I solve this problem? I have given my tried code of controller model and view
Reply
Answers (
1
)
How do i sum the value from each column from last row
printing using .net using window api