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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:32:36+00:00 2026-05-24T22:32:36+00:00

I’m working on my first ASP.NET MVC 3 application and I’ve got a couple

  • 0

I’m working on my first ASP.NET MVC 3 application and I’ve got a couple of actions defined to handle adding/removing an ice cream from a menu. They look like so:

[HttpPost]
public PartialViewResult AddMenuIceCreamMapping(int iceCreamId, int menuId)


[HttpPost]
public PartialViewResult RemoveMenuIceCreamMapping(int iceCreamId, int menuId)

In order for these actions to not result in a 404 error, I went into the Global.asax.cs file and added the following:

routes.MapRoute(
  "AddMenuIceCreamMapping", // Route name
  "IceCream/AddMenuIceCreamMapping/{iceCreamId}/{menuId}", // URLwith parameters
  new
  {
     controller = "IceCream",
     action = "AddMenuIceCreamMapping",
     iceCreamId = UrlParameter.Optional,
     menuId = UrlParameter.Optional
  } 
);

routes.MapRoute(
  "RemoveMenuIceCreamMapping", // Route name
  "IceCream/RemoveMenuIceCreamMapping/{iceCreamId}/{menuId}", // URLwith parameters
  new
  {
     controller = "IceCream",
     action = "RemoveMenuIceCreamMapping",
     iceCreamId = UrlParameter.Optional,
     menuId = UrlParameter.Optional
  } 
);

and those work, meaning I can click an Add or Remove button on my page and add or remove an ice cream/menu mapping. Great. But I’m expecting that there will be more situations like this and I can see this routes container having more entries such as these. And to my novice web programmer eye, it seems a bit clunky and I begin to think that perhaps I’m going about this the wrong way. Am I? Is there a better way to approach this so that I don’t end up doing the “go create some action that takes N parameters and then go add a route” thing. Any suggestions here?

  • 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-24T22:32:37+00:00Added an answer on May 24, 2026 at 10:32 pm

    You can use placeholders in your mappings to deal with this… Instead of what you’ve got above, you could use this (note that I don’t specify a default):

    routes.MapRoute(
                    "TwoParameterRoute", // Route name
                    "{controller}/{action}/{id1}/{id2}", // URL with parameters
                   );
    

    And if you have to add a route that takes three parameters, you extend the idea:

    routes.MapRoute(
                    "ThreeParameterRoute", // Route name
                    "{controller}/{action}/{id1}/{id2}/{id3}" // URL with parameters
                   );
    

    In a controller for the two parameter route, the code would look like this (for a contrived sample):

    public ActionResult Index(int id1, int id2)
        {
            ViewData["id1"] = id1;
            ViewData["id2"] = id2;
    
            return View();
        }
    

    One final thing to note is that you can change the naming to match a pattern you might have. In the first example, instead of id1 and id2 you might have entityId and relatedId or something similar.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
i got an object with contents of html markup in it, for example: string
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.