0

我正在尝试通过搜索和分页来查看视图,但是当搜索正常但是当我单击下一页链接时没有显示任何内容

[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>
4

2 回答 2

0

代码不清楚,无论如何,如果您单击下一页链接,您正在执行获取,而不是发布。因此,您应该在 get 方法中添加逻辑。

于 2013-02-20T16:15:50.517 回答
0

当您进行搜索时,您使用的是 HttpPost 方法,并且您的方法“Browse”在搜索和分页发生的地方执行。

当您点击下一页时,您将收到 HttpGet 请求(我想),并且您在“浏览(httpPost)中所做的任何事情都不会发生。

进入新页面需要您保留搜索条件、页码,并且在该方法中您需要再次获取数据集并进行分页。您可以将它们作为查询参数传递。

您拥有的另一个选项是使您的下一页请求成为 HTTPPost 请求并使其执行“浏览”(httpPost)

Fiddler 是您的朋友http://www.fiddler2.com/fiddler2/ 运行它,您将看到发送到服务器的具体内容、使用的动词等。

我希望这会有所帮助。

于 2013-02-20T16:37:33.240 回答