I have a controller method in ASP.NET MVC that looks like this:
public ActionResult GetAlbumPictures(int albumId) { var album = AlbumRepo.GetSingle(albumId); var pictures = album.Pictures; return View(pictures); }
The routing for this method is as follows:
routes.MapRoute(null, "pictures" new { controller = "Album", action = "GetAlbumPictures" });
The user will use the following URL to retrieve images filtered by album ID:
GET http:
However, I would like to change the querystring parameter of only album instead of albumid :
GET http:
This would mean that the controller method should be changed to:
public ActionResult GetPictures(int album) { ... }
However, this is not ideal, because now the method has a parameter called album , which can be confused as an album object instead of an ID album .
My question is, is there a way to configure ASP.NET MVC so that in routing it gets the querystring parameter named album , but then albumid it to the controller as the albumid parameter?
PS I know that I can do this in the routing table:
routes.MapRoute(null, "album/{albumId}/pictures", new { controller = "Album", action = "GetAlbumPictures" });
But due to obsolete issues, I have to get it working for the querystring method as well.