Search with multi field in asp.net mvc and sql server -
please me problem below:
i have 1 table in sql server field: product, customer, year, quantity,... , have search form 3 textbox: txtprod, txtcust, txtyear , search button
i want result:
- if of 3 textboxs null or empty: show of record
- if 1 of 3 textbox empty, searching 2 others conditions
- if 2 of 3 textbox empty, searching condition.
please me how write select in sql server or linq in asp.net mvc
thanks much!
assume value of txtprod, txtcust , txtyear filled prod, cust, , year variables in controller, , table map entity name entity
var items = entity in modelcontext.entity select entity; if (!string.isnullorempty(prod) && !string.isnullorwhitespace(prod)) { items = items.where(item => item.product == prod); } if (!string.isnullorempty(cust) && !string.isnullorwhitespace(cust)) { items = items.where(item => item.customer == cust); } if (!string.isnullorempty(year ) && !string.isnullorwhitespace(year )) { items = items.where(item => item.year == year ); } //return view filtered data hear. ex: return view(items);
i hope can particular problem
Comments
Post a Comment