mccalltd/AttributeRouting — Issue #22: Parameters in Index action
Author: shapper
Created: 2011-11-21 12:47:33+00:00
State: open

Hello,

I am defining a base route system for a CMS using Attribute Routing and I have the following:

[GET("users/page/{page=1}")]
public virtual ActionResult Index(Int32 page) {
return View();
} // Index

I am displaying "users/page/1" to because "users/1" is Users > Show.

If I need to filtrer users by Age and define a Sort Direction and Field I could use:

[GET("users/age/{age=10}/page/{page=1}/field/{field=username}/direction/{direction=asc} ")]
public virtual ActionResult Index(Int32 page, Int32 age, String field, String direction) {
return View();
} // Index

So I would get:

"users/age/10/page/1/field/username/direction/asc"

Does this make sense? Or should I use only something like:

"users?age=10&page=1&field=username&direction=asc"

I could also pass some of the parameters inside the model.

But I think having them on the url is better.

Thank You,
Miguel