RedirectToAction没有返回正确的页面 [英] RedirectToAction not returning correct page

查看:329
本文介绍了RedirectToAction没有返回正确的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Razor页面上的一些javascript进行帖子调用:



I am making a post call from some javascript on a Razor page:

<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:

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);
}





但似乎 Index.cshtml 页面显示而不是 SearchResults.cshtml 页面。



有什么问题?



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

What is wrong?

推荐答案

' #btn-search')。点击( function (){


.post( ../ Home / Search,{filter:
.post("../Home/Search", {filter:


' #txt-search')。val()}, null String
});
});
< / script >
('#txt-search').val()}, null, String) }); }); </script>





搜索(字符串过滤器)使用预期参数值成功调用





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

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);
}





但似乎 Index.cshtml 页面显示而不是 SearchResults.cshtml 页面。



有什么问题?



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

What is wrong?


这篇关于RedirectToAction没有返回正确的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆