Domanda

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.):

  • Name
  • Guid

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; }
}
È stato utile?

Soluzione

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 ;).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top