に新しいエンティティを追加することができますどのように私は次のようにSelectListのを開始し、次のアクションメソッドがあります: -私は動的に私のHtmlhelper.dropdownlist
public PartialViewResult Search(string q, int q2,string q3,string sortOrder)
{
ViewBag.q2 = new SelectList(elearningrepository.FindAllLevels().ToList(), "DifficultyID", "Description", 2);
ViewBag.q3 = new SelectList(elearningrepository.FindAllusers().ToList(), "UserID", "UserID",2);
ViewBag.today = DateTime.Today;
ViewBag.nextmonth = DateTime.Now.AddMonths(1);
var v = elearningrepository.searchquestions3(q, q2, q3);
return PartialView("_searchquestion", v);
}
そして、次のリポジトリ方法: -
public IQueryable<Question> searchquestions3(string q, int? q2 , string)
{
return from u in entities1.Questions
where (u.Description.Contains(q) && (u.DifficultyID == q2 || q2 == "Any") && (u.CreatedBy == q3 || q3 == "Any"))
select u;}
をその後、ビュー上で、私は以下のようにドロップダウンリストをレンダリング: -
<th>
@Html.DropDownList("q2")
</th>
</tr>
<tr>
<th>
Seach By Create By:-
</th>
<th>
@Html.DropDownList("q3")
</th>
しかし、ホq2 & q3ドロップダウンリストに「Any」という単語を表す新しい値を追加すると、リポジトリメソッドは意図したとおりに動作しますか?あなたはあなたのポストを取得し、あなたのコントローラにoptionLabel
を使用する必要が BR
ですが、AnyはIDの値なしでラベルとして挿入されます... –
yuor replyに感謝しますが、「あなたのoptionLabel == "Any"はユニークな何かをしますか? " –