我試圖硬編碼一些數據進行測試,但似乎無法得到此正常工作。我確信我缺少一些簡單的東西。不能隱式轉換類型爲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; }
}
任何幫助是非常感謝!
你會在哪一行發生錯誤。 –