Manoj Maharana

Manoj Maharana

  • NA
  • 362
  • 128k

MVC model for dynamic survey form step by step

Mar 31 2017 12:49 AM

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)