ASP.NET MVC - 控制器参数不是从表单收集? [英] ASP.NET MVC - Controller parameter not being gathered from form?

查看:119
本文介绍了ASP.NET MVC - 控制器参数不是从表单收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们现在有这个问题与控制器;控制器看起来是这样的:

We are having this problem with a controller right now; the controller looks like this:

public class AccountsController:Controller {
    public ActionResult List(int? page, int? pageSize, string keywords) {...}
}

我们正在通过jQuery发布此页:

We are posting to this page via jquery:

$.post("/myapp/Accounts/List",
       {"page":0,"pageSize":10,"keywords":"asdf"}, 
       updategrid,
       "json");
...
function updategrid(result) {...}

里面的动作:的Request.Form [关键词] ==ASDF,但关键字==在这里,我很茫然。为什么没有关键字有我们想要的价值呢?

Inside the action: Request.Form["keywords"] == "asdf", but keywords=="" and here I am at a loss. Why doesn't keywords have the value we want?

推荐答案

马克值得作为提供报价评论...答案

quoting answer provided as comment from Mark Worth...

如何为你的控制器的存在
  实例化?我有这个问题,我
  发现它是我的
  SpringControllerFactory创建我
  控制器为singleton(因此
  总是使用从值
  第一次请求)。 - 马克·沃斯5月19日
  8:19

How is your controller being instantiated? I had this problem and I found that it was my SpringControllerFactory creating my controllers as singletons (and hence was always using the values from the first request). – Mark Worth May 19 at 8:19

这就是它!我的控制器是
  注册为单到我
  温莎容器所以我
  WindsorControllerFactory返回
  单身。比尔 - 巴里5月19日
  18:14

That's it! My controller was registered as a singleton into my Windsor container so my WindsorControllerFactory returned a singleton. – Bill Barry May 19 at 18:14

这篇关于ASP.NET MVC - 控制器参数不是从表单收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆