问题描述
我有以下课程。
I have the following classes.
namespace SmartAdminMvc.Models
{
[Table("vwFeedback")]
public class Feedback
{ [Key]
public int ProjectID { get; set; }
public int FeedbackNo { get; set; }
public int CustomerPersonNo { get; set; }
public int QuestionSeq { get; set; }
public int QuestionID { get; set; }
public int Applicable { get; set; }
public string Answer { get; set; }
public string AnswerText { get; set; }
public string Question { get; set; }
public string QuestionAlt1 { get; set; }
public string QuestionAlt2 { get; set; }
public string AnsType { get; set; }
public string Option1 { get; set; }
public string Option2 { get; set; }
public string Option3 { get; set; }
public string Option4 { get; set; }
public string Option5 { get; set; }
}
}
namespace SmartAdminMvc.Models
{
public class FeedbackContext : DbContext
{
public DbSet<Feedback> Feedbacks { get; set; }
}
}
以下是我的控制器类
Following is my controller class
namespace SmartAdminMvc.Controllers
{
public class FeedbackController : Controller
{
// GET: Feedback
public ActionResult Index()
{
FeedbackContext feedbckContxt = new FeedbackContext();
List<Feedback> allFeedbcks = feedbckContxt.Feedbacks.ToList();
try{
foreach (var item in allFeedbcks)
{
System.Diagnostics.Debug.WriteLine("Answer " + item.Answer + " Question Id. " + item.QuestionID + " CustomerPersonNo " + item.CustomerPersonNo);
}
} catch(Exception exp){
Response.Write("Error:" + exp.ToString());
}
return View(allFeedbcks);
}
}
}
以下显示为输出
回答4问题ID。 1009 CustomerPersonNo 10002
答案4问题ID。 1009 CustomerPersonNo 10002
答案4问题ID。 1009 CustomerPersonNo 10002
答案4问题ID。 1009 CustomerPersonNo 10002
答案4问题ID。 1009 CustomerPersonNo 10002
答案4问题ID。 1009 CustomerPersonNo 10002
答案4问题ID。 1009 CustomerPersonNo 10002
答案4问题ID。 1009 CustomerPersonNo 10002
答案4问题ID。 1009 CustomerPersonNo 10002
答案4问题ID。 1009 CustomerPersonNo 10002
在输出上,它只打印表中的第一行值(重复)。但是获取的行数是正确的。
我一直在努力解决这个问题很长时间。如果有人可以帮助我,那将是一个很好的帮助。
谢谢
Following is shown as the output
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
Answer 4 Question Id. 1009 CustomerPersonNo 10002
On the Output it prints only the first row values (repeatedly) from the table. But the number of rows fetched is correct.
I have been struggling with this issue for very long . It will be a great help if someone could help me out.
Thanks
推荐答案
这篇关于[已解决]我无法获取整个表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!