4
Answers

MVC model for dynamic survey form step by step

MVC model for dynamic survey form step by step

 
Here is the html:
    1. @for (int i = 0; i < Model.Questions.Count(); i++)  
    2.                               {  
    3.                                   <div class="tab-pane active" id="tab1">  
    4.                                       @for (int k = 0; k < Model.Questions.Count(); k++)  
    5.                                   {  
    6.                                   <div class="row">  
    7.   
    8.                                       <div class="form-group">  
    9.   
    10.                                           <div class="col-md-12">  
    11.   
    12.                                               @*@Html.DisplayFor(model => model.Questions[k].QuestionText)*@  
    13.                                               
    14.                                               @*<br /><br />*@  
    15.                                               @for (int j = 0; j < Model.Answers.Take(1).Count(); j++)  
    16.                                               {  
    17.                                                     
    18.                                                       @Html.DisplayFor(model => model.Questions[k].QuestionText)  
    19.                                                       @*<label>3. When I am faced with a financial decision I am generally more concerned about the possible losses than the probable gains.</label>*@  
    20.                                                       <br /><br />  
    21.                                                       <div class="mt-checkbox-list">  
    22.                                                           <label class="mt-checkbox">  
    23.                                                               <input type="checkbox"> @Html.DisplayFor(model => model.Answers[j].AnswerText)  
    24.                                                               <span></span>  
    25.                                                           </label>  
    26.                                                           <label class="mt-checkbox">  
    27.                                                               <input type="checkbox">  @Html.DisplayFor(model => model.Answers[j].AnswerText)  
    28.                                                               <span></span>  
    29.                                                           </label>  
    30.                                                           <label class="mt-checkbox">  
    31.                                                               <input type="checkbox"> @Html.DisplayFor(model => model.Answers[j].AnswerText)  
    32.                                                               <span></span>  
    33.                                                           </label>  
    34.                                                           <label class="mt-checkbox">  
    35.                                                               <input type="checkbox">@Html.DisplayFor(model => model.Answers[j].AnswerText)  
    36.                                                               <span></span>  
    37.                                                           </label>  
    38.                                                           <label class="mt-checkbox">  
    39.                                                               <input type="checkbox"> @Html.DisplayFor(model => model.Answers[j].AnswerText)  
    40.   
    41.                                                               <span></span>  
    42.                                                           </label>  
    43.                                                       </div>  
    44.                                                     
    45.   
    46.                                           </div>  

 
 
  1. how do i bind the question answer multiple choice in a model and html.
  2. the above code not working properly.
  3. I want in tab1 4 questions with multiple choice and tab2 4 questions with multiple choice.
  4. here is the model:
  1.   public List<QuestionsModel> Questions { get; set; }  
  2.         public List<AnswerModel> Answers { get; set; }  
  3.   
  4. public class QuestionsModel  
  5.     {  
  6.         public string QuestionText { get; set; }  
  7.         public string QuestionComment { get; set; }  
  8.           
  9.     }  
  10.     public class AnswerModel  
  11.     {  
  12.         public string AnswerText { get; set; }  
  13.         public bool IsCorrect { get; set; }  
  14.     }  
can ayone guide me how do i create a model and html.so that it will bind question and answer in a survey form respectively in mvc4

Answers (4)

1
Photo of tri_inn
NA 1.2k 42.6k 8y
see these links if you get some idea.
 
https://forums.asp.net/t/2016395.aspx?Dynamic+Questionnaire+in+ASP+Net+MVC+4+0
https://www.codeproject.com/Articles/584161/Survey-Web-App-Using-ASP-NET-MVC-Entity-Framewor
https://www.codeproject.com/Articles/486564/ASP-NET-Simple-Survey-Application
http://stackoverflow.com/a/21930525/728750
https://www.twilio.com/docs/tutorials/walkthrough/automated-survey/csharp/mvc
http://highoncoding.com/Articles/645_Creating_Multiple_Choice_Exam_Application_Using_ASP_NET_MVC_Framework.aspx
http://ngalatalla.blogspot.in/2011/11/building-dynamic-quiz-application-in.html
http://20fingers2brains.blogspot.com/2013/05/simple-dynamic-quiz-in-aspnet-mvc3-razor.html

 
0
Photo of Manoj Maharana
NA 281 20.4k 8y
 
sir here is the sample of image. 
 
i am using this coding but not working.
 
  1. @foreach (var item in Model.ParentList)  
  2.                               {  
  3.                                   <div class="tab-pane active" id="tab1">  
  4.   
  5.                                       @foreach (var items in Model.ParentList)  
  6.                                       {  
  7.                                           <div class="row">  
  8.   
  9.                                               <div class="form-group">  
  10.   
  11.                                                   <div class="col-md-12">  
  12.   
  13.                                                       <label>@items.QuestionText</label>  
  14.   
  15.                                                       @foreach (var ch in Model.ChildList)  
  16.                                                       {  
  17.                                                           if (items.QuestionId == ch.QuestionId)  
  18.                                                           {  
  19.                                                               string id = @ch.QuestionId + "_" + @ch.AnswerId;  
  20.   
  21.                                                               <div class="icheck-list">  
  22.                                                                   <label class="icheck-list" id="@ch.AnswerId">  
  23.   
  24.                                                                       <input name="@ch.QuestionId" onclick="handlesClick(this);" id="@id" type="radio">@ch.AnswerText  
  25.                                                                       <span></span>  
  26.                                                                   </label>  
 
0
Photo of Manoj Maharana
NA 281 20.4k 8y
http://www.c-sharpcorner.com/forums/how-do-i-bind-4-tab-in-a-loop
0
Photo of Ramesh Palanivel
NA 9.5k 138.7k 8y
Hi Manoj,
 
Can you share some sample images for that?