My suggestion is to remove the "DefaultApi" route in RegsiterRoutes. (I assume you do not have a use for it) And then remove the {searchParameter} value in your route template. If you do this, you will not have to modify your javascript and it will route
correctly.
Or if you do want that route, you should flip the order of your DefaultApi and SearchWithParameter routes. The routing mechanism will select the first match in the order listed.
I believe you need to understand Routing. Steve Sanderson book's Routing chapter is an excellent starting point. After this just read this
link,
Note: Unnecessary route will drammatcally affect your application performance. See
this.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
public IQueryable<Order> SearchWithParameter(SearchOrderParameter searchParameter)
{
//Logic here
}
public Order SaveOrUpdate(Order order)
{
//Logic here
}
publicIQueryable<Order>SearchWithParameter(SearchOrderParameter searchParameter) { //Logic here }
publicOrderSaveOrUpdate(Order order) { //Logic here }
Thanks
Andy
I believe you are moving in the wrong direction. 1 route
!= 1 action. You should always create generic routes as much as possible otherwise it will affect your application performance.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Andyrandy
Member
1 Points
14 Posts
Re: How to write map/route for multiple Post
Mar 27, 2012 04:12 PM|LINK
Nope
davebettin
Member
313 Points
94 Posts
Re: How to write map/route for multiple Post
Mar 27, 2012 04:19 PM|LINK
Have you changed your routes as I specified earlier? This is pretty straighforward. Can you past your routes here again?
@dbettin
panesofglass
Member
730 Points
237 Posts
Re: How to write map/route for multiple Post
Mar 27, 2012 04:26 PM|LINK
Or if you do want that route, you should flip the order of your DefaultApi and SearchWithParameter routes. The routing mechanism will select the first match in the order listed.
davebettin
Member
313 Points
94 Posts
Re: How to write map/route for multiple Post
Mar 27, 2012 04:31 PM|LINK
With this use case this route will always be selected. Modifying the order won't help.
@dbettin
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: How to write map/route for multiple Post
Mar 27, 2012 05:10 PM|LINK
I believe you need to understand Routing. Steve Sanderson book's Routing chapter is an excellent starting point. After this just read this link,
Note: Unnecessary route will drammatcally affect your application performance. See this.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Andyrandy
Member
1 Points
14 Posts
Re: How to write map/route for multiple Post
Mar 29, 2012 03:01 PM|LINK
Hi Dave, Thanks for your time and reply, Code for Route is :
routes.MapHttpRoute( name: "SaveOrUpdate", routeTemplate: "api/{controller}/{action}", defaults: new { action = "SaveOrUpdate" } ); routes.MapHttpRoute( name: "SearchWithParameter", routeTemplate: "api/{controller}/{action}/{searchParameter}", defaults: new { action = "SearchWithParameter", searchParameter = RouteParameter.Optional } );and in controller its :
public IQueryable<Order> SearchWithParameter(SearchOrderParameter searchParameter) { //Logic here } public Order SaveOrUpdate(Order order) { //Logic here }Thanks
Andy
davebettin
Member
313 Points
94 Posts
Re: How to write map/route for multiple Post
Mar 29, 2012 05:06 PM|LINK
No problem. Are these working for you?
@dbettin
Andyrandy
Member
1 Points
14 Posts
Re: How to write map/route for multiple Post
Mar 29, 2012 10:53 PM|LINK
yes, above code is working for me....:)
Is this the best way to do it ?
davebettin
Member
313 Points
94 Posts
Re: How to write map/route for multiple Post
Mar 30, 2012 12:36 AM|LINK
Looks good.
@dbettin
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: How to write map/route for multiple Post
Mar 30, 2012 04:00 AM|LINK
I believe you are moving in the wrong direction. 1 route != 1 action. You should always create generic routes as much as possible otherwise it will affect your application performance.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD