# MVC 查詢功能(模糊查詢) ### index.cshtml * 新增一個name="abc"的form表單 > <form> <input type="text" name="abc"/> <input type="submit" value="提交"/> </form> > ### xxxController.cs 1. index帶入變數值 > public ActionResult Index(String abc){...} > 2. 取得資料庫資料 > var 資料集合 = db.資料表名稱.ToList(); > 3. 過濾條件 > if(abc != null) { 資料集合 = 資料集合.Where (x=>x.資料欄位名稱.ToString().Contains(abc)).ToList(); } > 4. 更改前台顯示畫面 > return View(資料集合); > ### 完整程式碼 > public ActionResult Index(String abc){ var 資料集合 = db.資料表名稱.ToList(); if(abc != null){ 資料集合 = 資料集合.Where (x=>x.資料欄位名稱.ToString().Contains(abc)).ToList(); } return View(資料集合); } >
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up