Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Routing in Web API

Posted on 2014-01-23
5
Medium Priority
?
596 Views
Last Modified: 2014-01-24
Hi,

I have this scenario. I have a route like this:

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

Open in new window


and I have a controller with 3 get's

        public DocResponse Get()
        {
            //some code
        }

        public DocResponse Get(string id, string search)
        {
            //some code
        }

        public PathResponse Get(string id)
        {
            //some code
        }

Open in new window


Now, if the url looks like this:

http://rest.smartdoc.se/api/documents

It runs the Get() function

If the url looks like this:

http://rest.smartdoc.se/api/documents/da46907f-c519-4d98-8279-6774afc651b4

it runs the Get(string id) function.

Now to my problem:

If the url looks like this:

http://rest.smartdoc.se/api/documents/fts/search%20string

I want to run the function Get(string id, string search) but it doesn't - it runs the Get(string id) function.

How can I force it to run like I want when two parameters are present?

Best regards
RTSol
0
Comment
Question by:RTSol
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39806335
My first guess would be that you need the "&" delimiter, since a %20 is HTML encoding for a space, which is not a parameter delimiter.

http://rest.smartdoc.se/api/documents/fts/search&string
0
 

Author Comment

by:RTSol
ID: 39806356
Hi,

Thats not it - it doesn't work for this either:

http://rest.smartdoc.se/api/documents/fts/searchstring

Best regards
RTSol
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 39806750
I shouldn't answer questions when I tired...

The route is {controller}/{action}/{id}/{search}, so what is the controller, action, ID, and search?

I believe that you can use named arguments as well.

Example:

public ActionResult GetImages(string id, string apiKey)

   ...

/Artist/GetImages/cher?apiKey=XXX
0
 

Author Comment

by:RTSol
ID: 39807043
Hi,

I am not sure I understand. In my controller I have this:

public DocResponse Get(string id, string search)

which to me has two named arguments of type string.

This call has two string parameters

http://rest.smartdoc.se/api/documents/fts/searchstring

but in the controller this is run:

public DocResponse Get(string id)

which has only one argument. Is there a problem with the route?

Even if I change to this:

defaults: new { controller = "Home", action = "Index" }

this is run:

public DocResponse Get(string id)

I probably need to understand how to set up the route properly.

Best regards
RTSol
0
 

Author Closing Comment

by:RTSol
ID: 39807059
Hi again,

I tested again with this:

http://rest.smartdoc.se/api/documents/fts?search=searchstring

and it works fine.

Thanks a lot!

RTSol
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question