我试图硬编码一些数据进行测试,但似乎无法得到此正常工作。我确信我缺少一些简单的东西。不能隐式转换类型为System.Collections.Generic.List
这里是我的代码:
public async Task<ActionResult> GetClusterAnswers(int clusterId, int sectionId)
{
contractorId = UserInfo.targetCompanyID;
var questions = await CommonClient.GetGeneralQandAsBySection(sectionId, contractorId);
var selectedQuestion = questions.FirstOrDefault(q => q.QuestionClusterID == clusterId);
int? questionid = selectedQuestion.QuestionID;
QuestionsWithPairedAnswers question = new QuestionsWithPairedAnswers();
question.QuestionID = questionid;
question.vchQuestionText = selectedQuestion.vchQuestionText;
question.vchTextElementOneHeader = selectedQuestion.vchTextElementOneHeader;
question.vchTextElementTwoHeader = selectedQuestion.vchTextElementTwoHeader;
question.Answers = new PairedAnswerTypes()
{
QuestionID = question.QuestionID,
PairedTextElementAnswerID = 1,
ContractorID = contractorId,
vchTextElementOne = "ABC",
vchTextElementTwo = "School Teachers"
};
return Json(question, JsonRequestBehavior.AllowGet);
}
这里是我的模型:
public class QuestionsWithPairedAnswers
{
[Key]
public int? QuestionID { get; set; }
public string vchQuestionText { get; set; }
public string vchTextElementOneHeader { get; set; }
public string vchTextElementTwoHeader { get; set; }
public List<PairedAnswerTypes> Answers { get; set; }
}
public class PairedAnswerTypes
{
public int PairedTextElementAnswerID { get; set; }
public int? QuestionID { get; set; }
public int ContractorID { get; set; }
public string vchTextElementOne { get; set; }
public string vchTextElementTwo { get; set; }
public virtual QuestionsWithPairedAnswers Question { get; set; }
}
任何帮助是非常感谢!
你会在哪一行发生错误。 –