问题描述
我正在使用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?
推荐答案
搜索(字符串过滤器)使用预期参数值成功调用
:
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没有返回正确的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!