Click here to Skip to main content
15,845,742 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making a post call from some javascript on a Razor page:

HTML
<input id="txt-search" type="search"/>
<input id="btn-search" type="submit" value="Go"/>

<script type="text/javascript" >
  (document).ready(function(){
    $('#btn-search').click(function(){
      $.post("../Home/Search", {filter: $('#txt-search').val()}, null, String)
    });
  });
</script>


Search(string filter) is successfully called with the expected parameter value:

C#
public void Search(string filter)
{
  List<SB_Detail> dets = db.SB_Details.ToList();
  if(filter != null)
  {
    dets = dets.Where(d=>d.SB_Model.ToUpper() == filter.ToUpper());
  }
  //This doesn't work
  RedirectToAction("SearchResults", "Home", new {details = dets});
}

//Never called?
public ActionResult SearchResults(List<SB_Detail> details)
{
  return View(details);
}


However it seems that the Index.cshtml page is displayed instead of the SearchResults.cshtml page as intended.

What is wrong?
Posted
Updated 31-Dec-13 21:26pm
v2
Comments
Zoltán Zörgő 1-Jan-14 2:35am    
As redirects are performed by the client, you c inspect with fiddler or IE developer toolbar what's really returned. Are yous ure your model passed via the two actions is properly encoded and decoded?

1 solution

hi you use void please replace with actionresult.
C#
public ActionResult Search(string filter)
{
  List<sb_detail> dets = db.SB_Details.ToList();
  if(filter != null)
  {
    dets = dets.Where(d=>d.SB_Model.ToUpper() == filter.ToUpper());
  }
  //This doesn't work
  RedirectToAction("SearchResults", "Home", new {details = dets});
}
 
Share this answer
 
v2
Comments
Andy_L_J 1-Jan-14 4:34am    
It doesn't make any difference: SearchResults() is not called.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900