gpt4 book ai didi

javascript - 通过 javascript 从 Controller View 调用不同的 Controller 操作

转载 作者:行者123 更新时间:2023-12-03 12:27:46 24 4
gpt4 key购买 nike

我有一个 Home Controller ,其 View 有一个按钮。我想在单击按钮时调用名为 SearchSpace 的 Controller 。

查看:

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

Controller

   [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 Controller 。请帮助我。

最佳答案

试试这个

      <button id="click"><a href="/Home/About">Click me</a>
</button>

关于javascript - 通过 javascript 从 Controller View 调用不同的 Controller 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24098369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com