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 7001153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:46:01+00:00 2026-05-27T20:46:01+00:00

Suppose I have defined route like that, context.MapRoute( Preview, /preview/{id}/{type}, new { controller =

  • 0

Suppose I have defined route like that,

        context.MapRoute(
            "Preview",
            "/preview/{id}/{type}",
            new { controller = "Preview", action = "Invoice", id = UrlParameter.Optional, type = UrlParameter.Optional }
        );

I have controller with action Invoice

public ActionResult(int id, string type)
{
  if (type == "someType") 
  {
    // ...
  } 
  else
  {
    // ..
  }
}

I want to get rid of If-Else case inside the action. Is it possible to attribute action somehow, so ASP.MVC would distinguish between both, like:

Just a pseudocode tho show idea?

[HttpGet, ActionName("Action"), ForParameter("type", "someType")]
public ActionResult PreviewSomeType(int id) {}

[HttpGet, ActionName("Action"), ForParameter("type", "someType2")]
public ActionResult PreviewSomeType2(int id) {}

Is something like that possible in MVC2/3 ?

  • 1 1 Answer
  • 3 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-27T20:46:01+00:00Added an answer on May 27, 2026 at 8:46 pm

    Action method selector

    What you need is an Action Method Selector that does exactly what you’re describing and are used exactly for this purpose so that’s not a kind of a workaround as it would be with a different routing definition or any other way. Custom action method selector attribute is the solution not a workaround.

    I’ve written two blog posts that will get you started with action method selection in Asp.net MVC and these kind of attributes:

    • Improving Asp.net MVC maintainability and RESTful conformance
      this particular post shows an action method selector that removes action method code branches what you’d also like to accomplish;
    • Custom action method selector attributes in Asp.net MVC
      explains action method selection in Asp.net MVC to understand the inner workings of it while also providing a selector that distinguishes normal vs. Ajax action methods for the same request;
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a route defined with several hardcoded (non-parameter) segments: routes.MapRoute(null, suggestion/list/by/{tag}, new {
Suppose I have a user defined type: CREATE OR REPLACE TYPE TEST_TYPE AS OBJECT
suppose I have a type defined as type value = None | Int of
Suppose I have a simple function defined that does nothing: function fn() { }
Suppose you have a python method that gets a type as parameter; is it
Suppose I have defined a unit of measure: [<Measure>] type Blob And I want
Suppose you have a general shape defined by a bunch of coordinate points that
I have a defined route that displays a dynamic page: page_show: url: /:domain_slug/:slug class:
Suppose I have some data types defined in PL/SQL: TYPE foo_t IS RECORD (...);
Suppose I have a method foo that is defined thus: void foo(MyObject a, MyObject

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.