asp.net mvc - I can't find a way to filter using PagedList -


well, assume problem it's pretty simple. second table... first 1 took 3 minutes load. looking way make faster found this: using nuget. can't make filter records. filter them once , show first page filtered, when click on page doesn't filter anymore. in bottom of partial view (where table displayed) have helper method filters. in here send page alone controller... in view (index) filter them brand send brand alone controller.

controller

public actionresult index(string brand_name, int? page)         {             //returns iqueryable<product> representing unknown number of products. thousand maybe?             //var products = myproductdatasource.findallproducts();             viewdata["brand_name"] = brand_name;             // if no page specified in querystring, default first page (1)             var pagenumber = page.hasvalue ? page.value : 1;              //viewbag.onepageofproducts = onepageofproducts;              if (!string.isnullorwhitespace(brand_name))             {                 // contain 12 products max because of pagesize                 ipagedlist<material> onepageofproducts = db.econtent_materialsfinalviewwithbcos                     .select(i => new material                     {                         brand = i.brand,                         category = i.category,                         language = i.language,                         bco = i.bco,                         materialcod = i.materialcod,                         derivation = i.derivation,                         artwork = i.artwork,                         bcodelivery = i.bcodelivery,                         materialid = i.materialid                     })                     .where(p => p.brand.tolower() == brand_name.tolower())                     .orderby(i => i.materialcod)                     .topagedlist<material>(pagenumber, defaultpagesize);                  return view("index", onepageofproducts);             }             else             {                 // contain 12 products max because of pagesize                 ipagedlist<material> onepageofproducts = db.econtent_materialsfinalviewwithbcos                     .select(i => new material                     {                         brand = i.brand,                         category = i.category,                         language = i.language,                         bco = i.bco,                         materialcod = i.materialcod,                         derivation = i.derivation,                         artwork = i.artwork,                         bcodelivery = i.bcodelivery,                         materialid = i.materialid                     }).orderby(i => i.materialcod).topagedlist<material>(pagenumber, defaultpagesize);                  return view("index", onepageofproducts);             }         } 

view

@using pagedlist.mvc <!--import our html helper-->  @model ipagedlist<econtentmvc.models.material>  <div style="padding-top: 5px"></div> @using (html.beginform("index", "materials", formmethod.get)) {     <div class="col-lg-3">         <div class="input-group">             <span class="input-group-btn">                 <button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i> search</button>             </span>             <input class="span2" id="appendedinputbutton" type="text" name="brand_name" placeholder="search brand for..." />                          </div><!-- /input-group -->     </div><!-- /.col-lg-3 -->     <div style="padding-top: 20px"></div>     <div id="grid-list">         @{ html.renderpartial("_ajaxmateriallist", model); }     </div>     } 

partial view

@using pagedlist.mvc <!--import our html helper-->  @model ipagedlist<econtentmvc.models.material>  <table>some table here</table> <div class="panel panel-primary filterable">     <div class="centeralign">         <!-- output paging control lets user navigation previous page, next page, etc -->         @html.pagedlistpager(model, page => url.action("index", "materials", new        {            //it awesome if have brand_name = brand            page        }))     </div> </div> 

when click on page number, getting brand_name => null or empty, in controller. see storing brand_name in viewdata, can retrieve again in view, , show in textbox, sent controller along page number. can way:

<input class="span2" id="appendedinputbutton" type="text" name="brand_name" placeholder="search brand for..." value="@viewdata["brand_name"]"/> 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -