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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:10:58+00:00 2026-05-18T20:10:58+00:00

I have two action methods that are called using the same action name, however,

  • 0

I have two action methods that are called using the same action name, however, depending on the actual parameter type depends which method should be called. This causes ambiguity. I created an attribute that determines if the parameter is a Guid and is the appropriate method.

[RequiredGuidParameter(ParameterName = "title")]
[ActionName("Title")]
public ActionResult Item_ById(Guid id)
{ ... }

[ActionName("Title")]
public ActionResult Item_ByName(string id)
{ ... }

The attribute looks like this:

    public string ParameterName = string.Empty;

    public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
    {
        object parameter = null;
        try
        {
            parameter = controllerContext.RouteData.GetRequiredString(ParameterName) as object;
            if (parameter != null)
            {
                Guid guid;
                return Guid.TryParse((string)parameter, out guid);
            }
        }
        catch { }

        parameter = controllerContext.RequestContext.HttpContext.Request[ParameterName] as object;
        if (parameter != null)
        {
                Guid guid;
                return Guid.TryParse((string)parameter, out guid);
        }

        return false;
    }

The ultimate goal being that if the parameter is a Guid run this method, otherwise move on, in which case it finds the next one. Is there a better way that does not invlove creating an additional route? Or perhaps a better way all around?

  • 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-18T20:10:59+00:00Added an answer on May 18, 2026 at 8:10 pm

    Why not something like:

    public ActionResult Item_Search(string id, Guid guid)
    {
        if( string.IsNullOrWhiteSpace(id) 
             SearchById();
         if( guid != new Guid() )
             SearchByGuid()
    }
    

    Non warranty’d psuedo code /\

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two action methods that are called using the same action name, however,
I have two applications written in Java that communicate with each other using XML
I have two methods, one called straight after another, which both throw the exact
I'm trying to provide a functionality of having two Methods one called StartTask(action mymethod)
I have two classes: Action and MyAction . The latter is declared as: class
i have two files one called stats.js one called storage.html in stats.js in contains
I have two questions, both related to the same view: so there is view
Let's say I have two classes that look like this: public class ByteFilter {
I have a class with two methods listed below. I call them from another
I have an Auction model with several attributes, two of which are current_auction:boolean and

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.