我有一個主控制器,其視圖有一個按鈕。我想調用一個名爲SearchSpace的控制器在按鈕單擊上。從控制器的視圖調用不同的控制器動作雖然javascript
查看:
<script type="text/javascript">
var data = { "id": "1" }
function search() {
alert("hello" + JSON.stringify(data));
$.ajax({
url: '/SearchSpace/searchSpace',
type: 'POST',
dataType: "json",
contentType: 'application/json',
data: JSON.stringify(data),
success: function (returnPayload) {
console && console.log("request succeeded");
},
error: function (xhr, ajaxOptions, thrownError) {
console && console.log("request failed");
}
});
}
</script>
控制器
[HttpGet]
public ActionResult searchSpace()
{
return View();
}
[HttpPost]
public ActionResult searchSpace(SearchSpace search)
{
//code
return View();
}
路由配置
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
警報調用,但它是不動的,以SearchSpace控制器.. 請幫助我。
你是什麼意思「不移動」?你的錯誤函數被調用了嗎? –
沒有錯誤消息顯示。移動含義調用該控制器操作 – Wasfa
您嘗試過ajax調用後的警報嗎? –