在这种情况下如何编写控制器 [英] How do I write my controller in this case

查看:84
本文介绍了在这种情况下如何编写控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在做一个问卷调查网页应用程序,我正在使用ASP MVC,



i这里有一个问题如何列出调查问卷和选项来自SQL DB我在View Page中穿了这个,我该怎么做我的控制器



i有3个表

调查:Id,Q1 .. ,Q11,修改日期,客户详情

问题:同上,文字

回答:同上,文字,价值

for exapmle



Q1:



a。优秀的b。非常好的c。好的d。弱势的没有



,每个选项的价值都很优秀:10,好:7等等。



任何帮助请:D



我尝试过:



< pre lang =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)/> } <} pre>

解决方案

您需要创建一个定义模型的类。您的模型将包含一些用于保存Question和SelectedAnswer的属性。然后,您将在Controller中使用该模型并将其保存到数据库中。以下是您可以参考的示例:使用ASP.NET MVC框架创建多项选择考试应用程序 [ ^ ]



这是另一个解释了如何实现实时答案: [ ^ ] http://vmsdurano.com/real-time-poll-vote-results-using-signalr-2 -mvc-web-api-2-jquery-and-highcharts /



如果您是ASP.NET MVC的新手,我建议您从基础开始首先,这样你就会知道MVC架构中的工作原理。 ASP.NET MVC | ASP.NET站点 [ ^ ]


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:

@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)  />                                                                                                                                                                                                                                                                                                                                                         }                                                                                                                                                                        }                                                } }

解决方案

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[^]


这篇关于在这种情况下如何编写控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆