Dandré
Dandré

Reputation: 2173

Binding request parameters to a specific method parameter

In ASP.NET MVC 2 (yes, TWO, I'm using MONO for this), I would like to know if it is at all possible to bind multiple Request parameters into an Action method parameter.

Let me give an illustration.

I'm passing 2 parameters (using whatever method I like, GET, POST, etc.):

Is there a way to bind those parameters to this:

public JsonResult MyMethod(NameClass identifier)

Instead of this:

public JsonResult MyMethod(string name, string guid)

Using this?

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

Upvotes: 2

Views: 182

Answers (1)

Levi Botelho
Levi Botelho

Reputation: 25214

Absolutely. You simply have to name your fields using dot notation as if you were going to access the property from inside the method. This means that the Guid field is named identifier.Guid and the Name field identifier.Name. It is too bad that you can't take advantage of strongly-typed user controls however ;).

Upvotes: 1

Related Questions