I want dynamic survey application in asp.net mvc any example all questions are true/false. any example.
Loading
I want dynamic survey application in asp.net mvc any example all questions are true/false. any example.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Deepak TewatiaRank #143 · 15.9K reputationPosted Dec 20, 2022, 1:56 PM EST
Hi mark,
I will guide you step by step, how to create dynamic survey application in ASP.NET MVC.
you need to create an ASP.NET MVC project in Visual Studio.
You can do this by selecting "File > New > Project" and then selecting "ASP.NET Web Application" from the list of templates.
On the next screen, select "MVC" as the project template.
then, you need to create a model to represent the survey questions and answers.
you can use the below code:
public class SurveyQuestion { public int ID { get; set; } public string Text { get; set; } public bool Answer { get; set; } }This model has three properties: ID, Text, and Answer.
The ID property is an integer that represents the unique ID of the question.
then, Text property is a string that contains the text of the question.
and last Answer property is a boolean that represents the correct answer to the question (true or false).
then, you need to create a controller and views to display the survey to the user and capture their answers.
you can use the below code:
here i am using list of hard coded questions you can fetch all from DB
public class SurveyController : Controller { private readonly List _questions = new List { new SurveyQuestion { ID = 1, Text = "Question 1", Answer = true }, new SurveyQuestion { ID = 2, Text = "Question 2", Answer = false }, new SurveyQuestion { ID = 3, Text = "Question 3", Answer = true } }; public ActionResult Index() { var model = _questions[0]; return View(model); } [HttpPost] public ActionResult Index(SurveyQuestion model) { var currentQuestion = _questions.FirstOrDefault(q => q.ID == model.ID); if (currentQuestion == null) { return RedirectToAction("Index"); } if (model.Answer == currentQuestion.Answer) { // Increment score } // Move to the next question var nextQuestion = _questions.FirstOrDefault(q => q.ID == model.ID + 1); if (nextQuestion == null) { // Survey is complete return RedirectToAction("Results"); } return View(nextQuestion); } public ActionResult Results() { // Display survey results return View(); } }This controller has three actions: Index, Index (POST), and Results.
The Index action displays the first question in the survey to the user.
and then Index (POST) action handles the form submission from the survey and checks the user's answer against the correct answer. If the answer is correct, it increments the score. If the answer is incorrect, it does not increment the score.
and last Results action displays the survey results to the user.
also need to create a view for each action in the controller.
index view : Index view should display the survey question and a form for the user to submit their answer.
Results View: Results view should display the survey results to the user.
Thanks
Aravind GovindarajRank #430 · 5.8K reputationPosted Dec 20, 2022, 1:45 PM EST
Please find the solution for the same
1. Create a page where you can enter survey questions, that supposes to be stored in your database. This option can able to do only by admin users.
2. Normal use can able to see the question that has been set it up by the admin. It means this user has an access only two methods in api i.e., GET and POST
GET => It uses to retrieve survey question
POST => It is used to insert the record.
While insert record you need to map, Question Number | UserId or User Name or Guest if anonymous user | True /False