问题描述
第一次搜索可以成功,成功后,搜索框的关键字就变空了,这个要怎么保存?翻了第2页,就又变回初始状态了下面是控制器代码,应该怎么修改呢?谢谢大家[HttpPost]publicActionResultRepairList(MF.Model.Repair.Repairmodel,intpageIndex=1){intTotalRecord=0;vardata=bll.GetRepairList(model.RepairNo,model.CityID,model.BuildingID,model.RoomNo,model.Contact,model.Tel,model.AppointTime,refTotalRecord,pageIndex,10);returnView(data);}
解决方案
解决方案二:
代码里面增加ViewBag.Query=model;
然后在cshtml里面进行对应的赋值@{MF.Model.Repair.RepairqueryModel=ViewBag.QueryasMF.Model.Repair.Repair;}<inputtype="text"value="@(queryModel==null?"":queryModel.RepairNo)"
解决方案三:
引用1楼starfd的回复:
代码里面增加ViewBag.Query=model;然后在cshtml里面进行对应的赋值@{MF.Model.Repair.RepairqueryModel=ViewBag.QueryasMF.Model.Repair.Repair;}<inputtype="text"value="@(queryModel==null?"":queryModel.RepairNo)"
还是不行,不知道哪里不对,搜索后,搜索关键字不变空,但是点击第2页后,调试会转到RepairList(intpageIndex=1),而不是RepairList(MF.Model.Repair.Repairmodel,intpageIndex=1),搜索关键字变空publicActionResultRepairList(intpageIndex=1){intTotalRecord=0;vardata=bll.GetRepairList(0,refTotalRecord,pageIndex,10);returnView(data);}[HttpPost]publicActionResultRepairList(MF.Model.Repair.Repairmodel,intpageIndex=1){ViewBag.Query=model;intTotalRecord=0;vardata=bll.GetRepairList(model.RepairNo,model.CityID,model.BuildingID,model.RoomNo,model.Contact,model.Tel,model.AppointTime,refTotalRecord,pageIndex,10);returnView(data);}
@usingMF.Model;@modelMF.Common.MvcPager.PagedList<MF.Model.Repair.Repair>@{MF.Model.Repair.RepairqueryModel=ViewBag.QueryasMF.Model.Repair.Repair;}@using(Html.BeginForm("RepairList","Repair",FormMethod.Post)){@Html.AntiForgeryToken();<tableclass="querycontion"><tr><th>单号</th><td><inputid="RepairNo"name="RepairNo"type="text"value="@(queryModel==null?"":queryModel.RepairNo)"/></td><th>姓名</th><td><inputid="Contact"name="Contact"type="text"value="@(queryModel==null?"":queryModel.Contact)"/></td><th>电话</th><td><inputid="Tel"name="Tel"type="text"value="@(queryModel==null?"":queryModel.Tel)"/></td></tr><tr><tdcolspan="8"style="text-align:right;"><inputtype="submit"name="btnSearch"class="btn80"value="搜索"/></td></tr></table>}