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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:53:10+00:00 2026-06-09T09:53:10+00:00

I created two action methods with a different name in the home controller public

  • 0

I created two action methods with a different name in the home controller

public ActionResult Default()
{
    ViewData["Message"] = "Welcome to ASP.NET MVC!";
    return View("index");
}

public ActionResult Index(int a)
{
    ViewData["Message"] = "Welcome to ASP.NET MVC! and Your Age is " + a;
    return View();
}

And my routing code look like:

routes.MapRoute(
  "Default1", // Route name
  "{Home}/{ID}", // URL with parameters
  new { controller = "Home", action = "Index", id =UrlParameter.Optional});

routes.MapRoute(
    "Default2", // Route name
    "{Home}", // URL with parameters
    new { controller = "Home", action = "Default" }
);

routes.MapRoute(
    "Default", // Route name
    "{controller}", // URL with parameters
    new { controller = "Home", action = "Default" }
);

But still getting problem

when I type URL like http://localhost:7221 then home is coming and Default() method invoking but if I type URL like

http://localhost:7221/Home then getting error. to handle this situation i define route like

routes.MapRoute(
    "Default2", // Route name
    "{Home}", // URL with parameters
    new { controller = "Home", action = "Default" }
);

But it is not working…….can u tell me why.

If I type URL like http://localhost:7221/Home/88 then Index(int a) method should be called but getting error. why

I want that when I type URL http://localhost:7221 or http://localhost:7221/Home then Default() should be called and when I will type

http://localhost:7221/Home/88 then Index(int a) should be invoked. What is wrong in my route? How can I rectify it? if possible rectify my route code. thanks

  • 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-06-09T09:53:11+00:00Added an answer on June 9, 2026 at 9:53 am

    The reason why you are having problems is that your routeparameters don’t match with the action method. Your action method requires int a, yet you are not providing it in any case, you are giving integer called id.

    What you should have in routevalues is:

            routes.MapRoute(
                name: "Home",
                url: "{controller}/{age}/{action}",
                defaults: new { controller = "Home", action = "Index", age = UrlParameter.Optional }
            );
    

    Note how age parameter is optional. Our controller should then look like this:

    public class HomeController : Controller
    {
    
        public ActionResult Index(int? age)
        {
            if ( age != null )
                ViewData["Message"] = "Welcome to ASP.NET MVC! and Your Age is " + age;
            else
                ViewData["Message"] = "Welcome to ASP.NET MVC!";
    
            return View();
        }
    }
    

    Ofcourse we could use parameter called id but I called it age for demonstration purposes.

    Update:

    Here’s something closer to your original request:

            routes.MapRoute(
                name: "Index_age",
                url: "{controller}/{age}/{action}/{id}",
                defaults: new { controller = "Home", action = "IndexA", id = UrlParameter.Optional }
            );
            routes.MapRoute(
                name: "Index",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
    

    Controller:

        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";
            return View();
        }
        public ActionResult IndexA(int age)
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC! and Your Age is " + age;
            return View("Index");
        }
    
    • 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'm trying to create two different routes on two different action methods like this:
I have created two imageViews promatically as shown below: public void createImageViews(Integer count){ ImageView[]
I created two classes in netbeans;One of them is a JPanel form and another
I created two dropdpwn calendar in my form with these codes: <script type=text/javascript src=http://code.jquery.com/jquery-latest.js></script>
I created two files in the App_GlobalResources folder: SiteResources.en-US.resx SiteResources.sp-SP.resx Both contain a value
I created two very simple Heroku apps to test out the service, but it's
I created two apps one free and one PRO and published them to the
I created two modules, one with def _func(): print hi and another def func():
I created two arrays. First the arrays show the elements with no order whatsoever.

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.