【问题标题】:How to use $.get method in asp.net mvc如何在 asp.net mvc 中使用 $.get 方法
【发布时间】:2013-01-21 19:49:48
【问题描述】:

我认为这段代码可以点击一个 ActionResult

 ClearFilters = function () {
        $.get("/Mandate/Index/1");
        window.location.href = '<%=Request.Url.Scheme + "://" + Request.Url.Authority + Request.Url.AbsolutePath%>';
    }

我的控制器方法

Public ActionResult Index(int? id)
{
     //some code
}

使用此代码,我可以点击索引操作结果,但我没有得到 int id 值 1?

这是我做错了吗?

谢谢

【问题讨论】:

  • 您是否为此类请求定义了路由?
  • 是的,我有。它以前可以工作,但现在不行。
  • 这闻起来像是路由问题。你能发布你的路线定义吗?

标签: jquery asp.net-mvc asp.net-mvc-2


【解决方案1】:

试试这个。看看你是否得到了 id 值,保持所有其他代码相同。

$.get("/Mandate/Index", { id=1 }, success: function(){
   window.location.href = '<%=Request.Url.Scheme + "://" + Request.Url.Authority + Request.Url.AbsolutePath%>';   
});

【讨论】:

  • 感谢 Shanker 我仍然没有在我的控制器操作中获得 id.. 的值。谢谢
  • 你为什么要在 $.get 调用之后设置location.href。你能在$.get的成功处理程序中做到这一点吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
  • 2020-05-03
  • 1970-01-01
  • 1970-01-01
  • 2010-11-10
相关资源
最近更新 更多