Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In MVC We Can Pass Multiple Id's in url like
Home/Index/1/1
C#
home/index/1/1
Posted
Updated 26-Oct-14 20:40pm
Comments
Sergey Alexandrovich Kryukov 27-Oct-14 2:17am    
Not clear. What's the problem?
—SA
sashkhdr 27-Oct-14 2:21am    
multiple id's
Sergey Alexandrovich Kryukov 27-Oct-14 2:24am    
I happened to read "multiple id's" twice, in the question. You just added these words for the 3rd time. Very smart...
—SA
sashkhdr 27-Oct-14 2:20am    
home/index/1/1
in this way we can pass in browser url in mvc

1 solution

If there is a requirement like this, see below explanation:-
Suppose we have an action Method that gets called in the URL like:-
C#
public ActionResult Example(int id, int exampleId)
{
    // other code goes here..
}

Now remember one thing the id parameter will always be one. You can see the routeconfig.cs in App_Start folder to check.
C#
routes.MapRoute(
           name: "Default",
           url: "{controller}/{action}/{id}",
           defaults: new
           {
               controller = "Home",
               action = "Index",
               id = UrlParameter.Optional
           }
       );


this is how the id is mentioned in routes.
But in our Action method we need exampleId also.
So our Url should look like for id=101 and example=201.
C#
Home/Example/101?exampleId=201

But the Url like you have mentioned is not possible. When you want to pass more than one Id then query strings would be used like I have mentioned & for more that 2 id you use & operator for adding query strings.
Hope this helps.
Post back your queries if any.
Thanks.
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900