Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3611036
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:49:39+00:00 2026-05-18T21:49:39+00:00

I have a controller method in ASP.NET MVC that looks like this: public ActionResult

  • 0

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 looks like this:

routes.MapRoute(null,
                "pictures"
                new { controller = "Album", action = "GetAlbumPictures" });

The user will use the following URL to get the pictures, filtered by the album ID:

GET http://server/pictures?albumid=10

However, I’d like to change the querystring parameter to just album instead of albumid:

GET http://server/pictures?album=10

This would mean that the controller method needs to be modified to:

public ActionResult GetPictures(int album)
{
    ...
}

However, this is not ideal because now the method has a parameter named album, which can be confused as an Album object instead of the ID of the Album.

My question is, is there any way of configuring ASP.NET MVC so that in the routing, it will receive a querystring parameter called album, but then pass it off to the controller as the albumId parameter?

P.S. 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 legacy issues, I have to make it work for the querystring method as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:49:40+00:00Added an answer on May 18, 2026 at 9:49 pm

    You can create a custom action filter attribute to handle this scenario. I haven’t tested this specific implementation, but the general idea is to do something like this:

    public class AlbumAttribute : ActionFilterAttribute
        {
             public override void OnActionExecuting(ActionExecutingContext filterContext)
             {
                 var albumId = filterContext.HttpContext.Request.QueryString["album"] as string;
                 filterContext.ActionParameters["albumId"] = albumId;
    
                 base.OnActionExecuting(filterContext);
             }
        }
    

    Then, decorate your action method with the [Album] attribute:

    [Album]
    public ActionResult GetAlbumPictures(int albumId)
    {
        var album = AlbumRepo.GetSingle(albumId);
        var pictures = album.Pictures;
        return View(pictures);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hallo, I have following jquery code for calling ASP.NET MVC controller method that is
In ASP.Net MVC if I have a method on a controller that returns a
I created a route in ASP.net MVC application that looks like this: routes.MapRoute( ArticleRoute,
I have multiple controller actions that takes an id public ActionResult Get(int? id) {
I have created a new ActionFilter for an ASP.NET MVC application that I'm creating.
This is going to sound quite bizarre. I have one ASP .NET MVC 2
I have a wizard in my asp.net MVC application which is built upon this
I have been developing in ASP.NET MVC for a short while. Up to this
In an ASP.net MVC 2 app that I have I want to return a
If you have a controller method like so: @expose(json) def artists(self, action=view,artist_id=None): artists=session.query(model.Artist).all() return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.