2010-02-20 4 views

Répondre

8

Remarque: Je ne suis pas sûr de Best, mais c'est ce que j'utilise.

Vous pouvez passer les arguments en utilisant le même nom pour tous:

Pour l'URL

http://localhost/MyController/MyAction?a=hi&a=hello&a=sup

Vous prendriez les paramètres comme un tableau de chaînes (ou liste).

public ActionResult MyAction(string[] a) 
{ 
    string first = a[0]; // hi 
    string second = a[1]; // hello 
    string third = a[2]; // sup 

    return View(); 
} 

Cela fonctionne pour POST et GET. Pour POST vous nommerez les contrôles <input> tous le même nom.

+0

+1: C'est cool. –

+0

Cela semble bon. Mais est-il possible de générer ce type d'URL avec Html.RouteLink? – Shameem

+0

Y a-t-il un nom pour ce type d'arguments dans ASP.NET MVC? (aide à googler plus à ce sujet) – Shameem

Questions connexes