我正在尝试使用搜索和分页查看但是当搜索正常但是当我点击下一页链接时没有显示任何内容
[HttpGet]
public ActionResult Browse()
{
return View();
}
[HttpPost]
public ActionResult Browse(FormCollection formContent ,int? page)
{
string cartype = !String.IsNullOrEmpty(formContent["Cartype"]) ? formContent "Cartype"] : "";
string SearchBox = !String.IsNullOrEmpty(formContent["searchbox"]) ? formContent["searchbox"] : "";
DateTime toDate = !String.IsNullOrEmpty(formContent["toDate"]) ? DateTime.Parse(formContent["toDate"]) : DateTime.MaxValue;
string Sort = formContent["sort"];
mvc4advertismentEntities2 db = new mvc4advertismentEntities2();
var result = AdvertFunObj.GetAdverts();
switch (Sort)
{
case "":
result = db.Mercedes.Where(m => m.CarType == cartype).ToList();
break;
case "price":
result = db.Mercedes.Where(m => m.CarType == cartype).OrderByDescending(m => m.Price).ToList();
break;
case "date":
result = db.Mercedes.Where(m => m.CarType == cartype).OrderByDescending(m => m.ExpirationDate).ToList();
break;
case "enginecapaity": result = db.Mercedes.Where(m => m.CarType == cartype).OrderByDescending(m => m.EngineCapacity).ToList();
break;
}
int pageSize = 6;
int pageNumber = (page ?? 1);
return View(result.ToPagedList(pageNumber, pageSize));
}
视图
<table class="advertbrowsediv " id="searcht" width="100%"><tr><td style="width: 42%"> فئة السياره :
<br />
<%: Html.DropDownList("Cartype", new SelectListItem [] {
new SelectListItem(){Text="مرسيدس",Value="مرسيدس", Selected=true},
new SelectListItem(){Text="ميتسوبيشي",Value="ميتسوبيشي"},
}) %>
</td>
<td >ترتيب حسب :
<br />
<%: Html.DropDownList("sort", new SelectListItem [] {
new SelectListItem(){Text="",Value="", Selected=true},
new SelectListItem(){Text="التاريخ",Value="date"},
new SelectListItem(){Text="السعر",Value="price"},
new SelectListItem(){Text="سعة المحرك",Value="enginecapaity"},
},
</td><td><br /><input style=" float:right" type="submit" value="بحث>
</table>
答案 0 :(得分:0)
代码不清楚,无论如何,如果你点击下一页链接,你正在执行获取,而不是帖子。所以你应该为你的get方法添加逻辑。
答案 1 :(得分:0)
当你进行搜索时,你正在使用HttpPost方法,你的方法“浏览”会在搜索和分页发生的地方执行。
当你点击下一页时,你会有HttpGet请求(我推测),无论你在“浏览(httpPost)”中做什么都不会发生。
转到新页面将要求您保留搜索条件,页码,并且在该方法中,您需要再次获取数据集并执行分页。您可以将它们作为查询参数传递。
您拥有的另一个选项是使您的下一页请求成为HTTPPost请求并使其执行“Browse”(httpPost)
Fiddler是你的朋友http://www.fiddler2.com/fiddler2/ 运行它,您将看到究竟发送到服务器的内容,使用的动词等等。
我希望有所帮助。