我在MVC实体框架模型中的几个表中创建了一个新模型。
namespace Prototype_07.Models
{
public class MyQuestionModel
{
public Questionaire Questionaire { get; set; }
public QuestionaireSection QuestionaireSection { get; set; }
public Section Section { get; set; }
public SectionQuestion SectionQuestion { get; set; }
public Question Question { get; set; }
public QuestionType QuestionType { get; set; }
public QuestionAnswerListCode QuestionAnswerListCode { get; set; }
public AnswerListCode AnswerListCode { get; set; }
}
}
我的控制器代码是:
public class MyQuestionController:Controller { private PrototypeEntities db = new PrototypeEntities();
public ActionResult Index()
{
var viewModel = from qa in db.Questionaires
join qas in db.QuestionaireSections on qa.QuestionaireKey equals qas.QuestionaireKey
join s in db.Sections on qas.SectionKey equals s.SectionKey
join sq in db.SectionQuestions on s.SectionKey equals sq.SectionKey
join q in db.Questions on sq.QuestionKey equals q.QuestionKey
join qtc in db.QuestionTypes on q.QuestionTypeKey equals qtc.QuestionTypeKey
join qddl in db.QuestionAnswerListCodes on q.QuestionKey equals qddl.QuestionKey
join ddl in db.AnswerListCodes on qddl.AnswerListCodeKey equals ddl.AnswerListCodeKey
where qa.QuestionaireName.Equals("TAD")
select new MyQuestionModel
{
Questionaire = qa,
QuestionaireSection = qas,
Section = s,
SectionQuestion = sq,
Question = q,
QuestionType = qtc,
QuestionAnswerListCode = qddl,
AnswerListCode = ddl
};
return View(viewModel);
}
我希望创建一个类似于Image
的视图在我看来,我一直坚持如何对问题进行分组并填充下拉列表。什么是MVC方式?
<table>
<tr>
<th>@Html.DisplayFor(model => Model.First().Questionaire.QuestionaireName)</th>
</tr>
@foreach (var item in Model.OrderBy(x => x.QuestionaireSection.DefaultSequence).OrderBy(x => x.SectionQuestion.DefaultSequence).OrderBy(x => x.QuestionAnswerListCode.DefaultSequence)) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Section.SectionName))
</td>
<td>
@Html.DisplayFor(modelItem => item.Question.Question1)
</td>
<td>
@Html.DropDownListFor(??????)
</td>
</tr>
}
</table>
答案 0 :(得分:0)
试试这个:
@Html.DropDownListFor(modelItem => item.QuestionAnswerListCode.AnswerList, @Model.AnswerListCode)
我认为如果你展示了表格的属性也会有所帮助。