【问题标题】:Binding request parameters to a specific method parameter将请求参数绑定到特定的方法参数
【发布时间】:2012-11-22 02:03:25
【问题描述】:

在 ASP.NET MVC 2(是的,两个,我为此使用 MONO)中,我想知道是否可以将多个请求参数绑定到一个 Action 方法参数中。

让我举例说明。

我正在传递 2 个参数(使用我喜欢的任何方法,GET、POST 等):

  • 姓名
  • 指南

有没有办法将这些参数绑定到这个:

public JsonResult MyMethod(NameClass identifier)

而不是这个:

public JsonResult MyMethod(string name, string guid)

用这个?

public class NameClass
{
    public string Guid { get; set; }
    public string Name { get; set; }
}

【问题讨论】:

标签: c# asp.net-mvc-2 parameterbinding


【解决方案1】:

当然。您只需使用点符号来命名您的字段,就好像您要从方法内部访问该属性一样。这意味着 Guid 字段被命名为 identifier.Guid 并且 Name 字段被命名为 identifier.Name。但是,您不能利用强类型的用户控件,这太糟糕了;)。

【讨论】:

  • 感谢您的快速回复。快速检查一下。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-08
  • 2020-04-15
  • 2016-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多