重定向到另一个具有多个参数的视图,位于不同的控制器 jQuery 中



我正在研究 mvc,我被困在一个地方,我想从一个视图重定向到另一个视图,

我的控制器中有 2 种方法,我想从一个重定向到另一个,

这是我的方法,

public ActionResult Test1()
{
return View();
}
[HttpGet]
public ActionResult Rest2()
{
return View();
}

和我的阿贾克斯电话

var url = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/") + 1);//to get current url
$.ajax({
url:  "@Url.Action("../RegForm/Rest2")",
type: "GET",
contentType: "application/json; charset=utf-8",
async: true,
error: function (error) {
},
success: function (response) {
}
});

调试器将转到我的控制器,但返回相同的视图

我能在这里做什么?

如果你想重定向,你绝对不需要AJAX。仅当您希望保持在同一页面上并仅更新其中的一部分时,才使用 AJAX。

因此,如果您只想重定向浏览器:

var url = '@Url.Action("Test2", "Home",new { ID=1, Name="LMK", Date="05-10-18" })'; 
window.location.href = url

最新更新