मुझे अपने व्यूमोडेल से जुड़ने के लिए एक चुनिंदा सूची नहीं मिल सकती है।व्यूमोडेल के साथ एक चयन सूची कैसे बांधें?
<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>
:
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);
}
और मेरे विचार में कोड इस तरह दिखता है:
मैं एक 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 = "";
}
}
इस नियंत्रक होता है
व्यू प्रश्न इकाई की Question_Type को चयनित मान पर सेट करता है, लेकिन जब मैं फॉर्म जमा करता हूं, वें ई प्रमाणीकरण संदेश ट्रिगर करने के लिए ??
Model.Question.Question_Type Model.Question.type_code 2 अलग-अलग गुण हैं? आपके पास Question.type_code के लिए एक सत्यापन संदेश है, लेकिन आप Question_Type सेट कर रहे हैं? –