asp.net - Why won't my search box return any results? -
i using asp.net mvc5 , trying add textbox above table search items in table. in view have
@using (html.beginform()) { <p> find start/end point @html.textbox("searchstring") <input type="submit" value="search" /> </p> }
then in controller
public actionresult index(string sortorder, string searchstring) { var lift = l in db.lifts select l; if (!string.isnullorempty(searchstring)) { lift = lift.where(l => l.startpoint.contains(searchstring) || l.endpoint.contains(searchstring)); } return view(lifts.tolist()); } }
however returns same table every time. silly doing wrong can't see.
try using this:
@using (html.beginform("index","controllername",new { sortorder = "desc/asc" },formmethod.post)) { <p> find start/end point @html.textbox("searchstring") <input type="submit" value="search" /></p> }
action code:-
public actionresult index(string sortorder, string searchstring) { var lift = l in db.lifts select l; if (!string.isnullorempty(searchstring)) { lift = lift.where(l => l.startpoint.contains(searchstring) || l.endpoint.contains(searchstring)); } return view(lifts.tolist()); } }
Comments
Post a Comment