【问题标题】:redirect to another view with multiple parameter, located in different controller jquery重定向到具有多个参数的另一个视图,位于不同的控制器 jquery
【发布时间】:2018-10-04 13:22:57
【问题描述】:

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

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

这是我的方法,

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

还有我的 ajax 调用

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

    }
});

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

我可以在这里做什么?

【问题讨论】:

  • 您是否希望从一个控制器重定向到另一个操作? return RedirectToAction("Home", "Details", new { area = "" });
  • 更新了我的问题

标签: jquery ajax model-view-controller actionresult


【解决方案1】:

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

所以如果你只想重定向浏览器:

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

【讨论】:

  • 如果 URL 包含一些变量怎么办?像 url 包含 3 个变量?
  • Test2 包含 ID 名称、日期、
猜你喜欢
  • 1970-01-01
  • 2017-09-25
  • 2014-07-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-26
  • 1970-01-01
  • 2014-01-08
  • 2014-12-06
相关资源
最近更新 更多