[英]The gridview data in my web application is not corresponding to the selection chosen from the dropdownlist
[英]How to display in my view the folders corresponding to my selection in a DropDownList?
我是一個初學者,我正在嘗試用C#編寫應用程序。
我想通過一個使用Enum
的DropDownList
進行過濾。 有人可以告訴我如何在控制器中進行操作,以便在視圖中選擇“ Complete
時僅顯示完整的文件嗎?
這是我的班級樣子:
namespace Client.Models
{
public enum StadeProg1
{
Complet, Incomplet
}
public class Programmes1
{
public int Programmes1Id { get; set; }
public DateTime MiseEnVenteDateProg { get; set; }
public StadeProg1? StadeProg { get; set; }
public virtual ICollection<Commentaire> Commentaire { get; set; }
public virtual ICollection<DocSource> DocSource { get; set; }
}
}
這就是我的見解:
<p>
@Html.DropDownList("Etat", EnumHelper.GetSelectList(typeof(StadeProg1)), "Etat", new { @class = "form-control" })
</p>
預先感謝您的幫助
謝謝,
我已經在controller
成功使用以下代碼:
ViewBag.Etat = Etat;
if (Etat.HasValue)
{
if (Etat == StadeProg1.Complet)
programmes1 = programmes1.Where(p =>
p.StadeProg==StadeProg1.Complet);
else
programmes1 = programmes1.Where(p =>
p.StadeProg==StadeProg1.Incomplet);
}
我也改變了view
:
@using (Html.BeginForm("Index", "Programmes1", FormMethod.Get, new { id
= "filterForm" }))
{
<p>
@Html.DropDownList("Etat", EnumHelper.GetSelectList(typeof(StadeProg1)),
"Etat",
new { @class = "form-control", onchange =
"document.getElementById('filterForm').submit();" })
</p>
}
我離開我所做的一切,以防它可以幫助另一個人。 即使我確定他有更好的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.