Click here to Skip to main content
15,924,317 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ,i'm doing a questionnaire web application and i'm using ASP MVC ,

i have a problem here how can list the questionnaire questions and options from SQL DB i wore this in View Page , what should i do in my controller

i have 3 tables
Survey : Id, Q1 .. ,Q11 , Date Modified , Customer Details
Questions: Id, Text
Answers : Id, Text , Value
for exapmle

Q1:

a. excellent b. very good c. good d. weak e. none

and each option has a value like excellent : 10 , good : 7 and ect.

any help please :D

What I have tried:

C#
@using (Html.BeginForm("SurveyQuestions", "ESurvey", FormMethod.Post))  {  
   @Html.AntiForgeryToken()  
       @Html.ValidationSummary(true)   
   for (int i = 0; i    
                     @for (int k = 0; k                                 
                                                       
                                                       
  @for (int j = 0; j  model.Questions[k].Text_ar)                                                                                                             
                                                                                                                                                                                         @Html.DisplayFor(model=> model.Answers[j].Answer_text)                                                                                                                            model.Answers[j].Answer_weight)/>                                                                                                                                                                                                                                                                                                                 @Html.DisplayFor(model=> model.Answers[j].Answer_text)                                                                model.Answers[j].Answer_weight)/>                                                                                                                                                                                                                                                        @Html.DisplayFor(model=> model.Answers[j].Answer_text)                                                                                                                           model.Answers[j].Answer_weight)  />                                                                                                                                                                                                                                                       @Html.DisplayFor(model=> model.Answers[j].Answer_text)                                                                                                                           model.Answers[j].Answer_weight)  />                                                                                                                                                                                                                                                       @Html.DisplayFor(model=> model.Answers[j].Answer_text)                                                                                                                           model.Answers[j].Answer_weight)  />                                                                                                                                                                                                                                                                                                                                                         }                                                                                                                                                                        }                                                } }
Posted
Updated 16-Dec-18 16:23pm
v2

1 solution

You need to create a class that defines your model. Your model will contain a few properties for holding the Question and SelectedAnswer. You will then use the model in your Controller and save them into your database. Here's on example you can refer: Creating Multiple Choice Exam Application Using ASP.NET MVC Framework[^]

Here's another one that explains how to implement real-time answers:[^]http://vmsdurano.com/real-time-poll-vote-results-using-signalr-2-mvc-web-api-2-jquery-and-highcharts/

If you are new to ASP.NET MVC, I would recommend you to start at the basics first so you will know how stuff works in MVC architecture. ASP.NET MVC | The ASP.NET Site[^]
 
Share this answer
 
Comments
muna901 17-Dec-18 2:49am    
thank you. i'll try that :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900