我有以下操作方法發起的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>
但是ho w我可以添加一個表示「Any」字的新值到q2下拉列表中,以便存儲庫方法能夠按預期工作? BR
但任何將被插入作爲一個標籤沒有任何價值的ID ... – 2012-03-12 14:24:04
感謝您的回覆,,但你的意思是「你不能然後在你的控制器使用條件,如果你的optionLabel == 「任何」然後做一些獨特的? 「 – 2012-03-12 14:27:42