I have mutiple questions and answer in the list. i need to display in view like (suppose i have 30 questions and answers) from that list i'm goign to display first 5 questions and answers with next button and again if i click on next button next 5 questions and answers and so on until 30 questions over and finish the test(means submit the questions and answers).
In Controller
public ActionResult Solution()
{
List items;
decimal testid = 1;
decimal skillId = 1;
items = (from p in db.ALBulkTestDetails
where ( p.TestID == testid && p.SkillID == skillId)
select new QuestionsModel
{
ID = p.QuestionID,
SkillId = p.SkillID,
QuestionText = p.Question,
Options = (from a in db.ALBulkTestDetails
join b in db.ALBulkTestDetails
on new { aa = a.QuestionID, a.SkillID } equals new { aa = b.QuestionID, b.SkillID }
where b.QuestionID == p.QuestionID && b.SkillID == p.SkillID
select new Answer
{
AnswerId = b.AnswerId,
Option1 = b.Option1,
Option2 = b.Option2,
Option3 = b.Option3,
Option4 = b.Option4
}).ToList()
}).ToList();
Session["itemsTimerCount"] = items.Count();
return View(items);
}
In View :
@model List
@{
ViewBag.Title = "Solution";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm("Solution", "Home", FormMethod.Get, new { enctype = "multipart/form-data" }))
{
ASP.NET TEST
@{int i = 0;}
@for (int j = 0; j < Model.Count; j++)
{
i++;
@Html.HiddenFor(m => m[j].ID)
@Html.HiddenFor(m => m[j].SkillId)
@i) @Html.DisplayFor(m => m[j].QuestionText)
foreach (var k in Model[j].Options)
{
@Html.RadioButtonFor(m => m[j].SelectedAnswer, "1")
@Html.RadioButtonFor(m => m[j].SelectedAnswer, "2")
@Html.RadioButtonFor(m => m[j].SelectedAnswer, "3")
@Html.RadioButtonFor(m => m[j].SelectedAnswer, "4")
}
}
}
Please help me how to do ?Thanks in Advance
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jagan MohanPosted Dec 9, 2015, 6:49 AM
Manas MohapatraPosted Dec 8, 2015, 11:36 AM