无法使用Revel检索表单参数

时间:2016-02-28 17:37:28

标签: go revel

我无法使用Revel检索表单数据。我能够检索查询参数。

我有这个控制器来测试$ cd /tmp/ $ lektor quickstart Lektor Quickstart ================= This wizard will generate a new basic project with some sensible defaults for getting started quickly. We jsut need to go through a few questions so that the project is set up correctly for you. Step 1: | A project needs a name. The name is primarily used for the admin UI and | some other places to refer to your project to not get confused if multiple | projects exist. You can change this at any later point. > Project Name: flow-example Step 2: | This is the path where the project will be located. You can move a | project around later if you do not like the path. If you provide a | relative path it will be relative to the working directory. > Project Path [/tmp/flow-example]: Step 3: | Do you want to generate a basic blog module? If you enable this the | models for a very basic blog will be generated. > Add Basic Blog [Y/n]: n Step 4: | Your name. This is used in a few places in the default template to refer | to in the default copyright messages. > Author Name [Brendan M. Sleight,,,]: That's all. Create project? [Y/n] Y $ cd flow-example/ $ echo "[fields.extra] > label = Extra > type = flow > flow_blocks = text" >>./models/page.ini $ cat ./models/page.ini [model] name = Page label = {{ this.title }} [fields.title] label = Title type = string [fields.body] label = Body type = markdown [fields.extra] label = Extra type = flow flow_blocks = text $ lektor server * Project path: /tmp/flow-example/flow-example.lektorproject * Output path: /home/bms/.cache/lektor/builds/76682e6a8f99116f0da91bcf96203e94 Started source info update * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) Finished source info update in 0.05 sec Started build U index.html U about/index.html U projects/index.html Finished build in 0.12 sec Started prune Finished prune in 0.00 sec ```

的内容
c.Params

当我传递查询参数(testkey,value)时,我得到:

func (c UserController) SaveUser() revel.Result {
    return c.RenderJson(c.Params) //just for check the content
}

一切都好。但是当我通过一个表格参数并且我没有得到任何数据时:

{
  "Values": {
    "testkey": [
      "value"
    ]
  },
  "Fixed": null,
  "Route": null,
  "Query": {
    "testkey": [
      "value"
    ]
  },
  "Form": null,
  "Files": null
}

这是{ "Values": {}, "Fixed": null, "Route": null, "Query": {}, "Form": null, "Files": null } 请求,我使用邮递员传递表格参数。

感谢。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。我必须传递form params作为方法参数:

// id and nickname are form params
func (c UserController) SaveUser(id, nickname string) revel.Result {
    return c.RenderJson(c.Params)
}