How to use a where clause in MVC ef | 首都客運時刻表查詢網
![How to use a where clause in MVC ef](https://i.imgur.com/2oxSoeJ.png)
2012年4月18日—UsingMVCEF,howwouldIfilterresultsbyafieldotherthantheid?returnView(db.Drafts.Where(PublicationId=id));.PublicationIdisa ...
![How to use a where clause in MVC ef](https://i.imgur.com/2oxSoeJ.png)
Im not sure what your Draft class looks like, but lets pretend it looks something like this:
public class Draft { public int Id { get; set; } public int PublicationId { get; set; } public string Name { get; set; } }You could write a query like this:
return View(db.Drafts.Where(d => d.Name == "foo"));This would only return Drafts that had a name of "foo". This by itself probably isnt useful. You would more than likely want to control this by passing data into your controller (query string, form value, route value, etc.):
public ActionResult Index(int id, string filter) { return View(db.Drafts.Where(d => d.Name == filter)); }Or you could filter on multiple properties:
public ActionResult Index(int id, string filter) { return View(db.Drafts.Where(d => d.Name == filter && d.PublicationId == id)); }
mvc查詢範例 MVC 關鍵字查詢 mvc搜尋 Mvc linq where and MVC where C# where clause Model MVC C# MVC mvc查詢範例 MVC 關鍵字查詢 mvc搜尋 Mvc linq where and MVC where C# where clause Model MVC C# MVC Asp NET 搜尋功能 C# 搜尋功能 MVC 題目 Asp search ASP NET 練習 Pagedlistpager POST ASP .net MVC 鐵人賽 MVC 加入 檢視 Dotnet new mvc mvc網站範例 MVC C# 範例 mvc架構範例 MVC 關鍵字 搜尋 Asp NET MVC 練習 mvc範例 竹東公車時刻表 5620時刻表 嘉義7315公車時刻表 豐原客運時刻表 梅山公車站到太平雲梯要多久 7313 公車時刻表 7323公車時刻表 9026時刻表查詢
ASP.NET MVC 從入門到放棄(Day21) | 首都客運時刻表查詢網
2021年9月26日 — 接下來講講查詢部分... Controller public ActionResult Index(string id) String SearchString = id; try if (... Read More
How to use a where clause in MVC ef | 首都客運時刻表查詢網
2012年4月18日 — Using MVC EF, how would I filter results by a field other than the id? return View(db.Drafts.Where(PublicationId=id));. PublicationId is a ... Read More
[ASP.NET MVC] 指令問題>> 在controlller裡寫where拿出選定 ... | 首都客運時刻表查詢網
2015年7月28日 — 接著我想說不如換成符合MVC架構的方式--在controller裡拿好東西後再丟給view呈現. 參考了我上個問題一位大大靠後的回覆的方式. (以下引用自那個回復). Read More
[ASP.NET MVC] 新增查詢功能 | 首都客運時刻表查詢網
2016年8月26日 — [ASP.NET MVC] 在Index新增查詢功能,依照電影名稱與類型查詢電影。 修改Index Form. 首先,先修改MoviesController的Index Action方法: public ... Read More
第7部分:將搜尋新增至ASP.NET Core MVC 應用程式 | 首都客運時刻表查詢網
2021年9月27日 — ASP.NET Core MVC 之教學課程系列的第7部分。 Read More
相關資訊整理