重定向到c#中的操作查看页面

时间:2014-02-10 13:54:36

标签: c# jquery asp.net ajax asp.net-mvc

我正在使用ajax $ .post调用重定向到Index的操作,从Index我需要调用它的View页面,同时调试它进入查看页面,但我在浏览器中看不到相同的内容。这是我的ajax代码和操作代码:

AJAX代码:

$("#btnSearch").click(function () {       
    var val=$('#whereSearch').val();         
    $.post("Search/Index/",{where:val});       
});

行动守则:

public ActionResult Index(string where)            
{     
    var q = searchQuery(where);  
    ViewBag.val = q;         
    return View();
}

1 个答案:

答案 0 :(得分:0)

为什么要使用AJAX呢?您将视图作为数据传回,您将无法获得重定向。就这样做:

 $("#btnSearch").click(function (e) { 
     e.preventDefault();     
     var val=$('#whereSearch').val();  
     window.location = "Search/Index/" + val;
});