Я не могу получить список выбора для привязки к моей ViewModel.
У меня есть ViewModel, который содержит сущность вопроса и строку
public class QuestionViewModel
{
public Question Question { get; set; }
public string RefUrl { get; set; }
public QuestionViewModel()
{
}
public QuestionViewModel(Question question, string RefUrl)
{
this.Question = question;
this.RefUrl = RefUrl;
}
public QuestionViewModel(Question question)
{
this.Question = question;
this.RefUrl = "";
}
}
, это контроллер:
public ActionResult Edit(int id)
{
Question question = db.Question.Single(q => q.question_id == id);
QuestionViewModel qvm = new QuestionViewModel(question);
ViewBag.category_id = new SelectList(db.Category, "category_id", "category_name", qvm.Question.category_id);
ViewBag.type_code = new SelectList(db.Question_Type, "type_code", "type_description", qvm.Question.type_code);
return View(qvm);
}
и код на мой взгляд, выглядит следующим образом:
<div class="editor-label">
@Html.LabelFor(model => model.Question.type_code, "Question_Type")
</div>
<div class="editor-field">
@Html.DropDownListFor(model => Model.Question.Question_Type, (SelectList)ViewBag.type_code)
@Html.ValidationMessageFor(model => model.Question.type_code)
</div>
Представление устанавливает для объекта Question для объекта Question_Type выбранное значение, но когда я отправляю форму, ValidationMessageFor триггеры ??