0

I was wondering how Do I pass a string as a paramter and how .net determines which get is applied and returned.

I am trying

 http://localhost:55304/api/WebPortal/Get/System.WorkItem.Incident

But its not working just get a resource is not found. The below is in my WebPortal Controller.

   private WebPortEnterpriseManagementDa _da = new WebPortEnterpriseManagementDa();
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    public ManagedType Get(string name)
    {

        ManagedType items = _da.GetManagedType(name);

        return items;
    }
csharpdude77
  • 3,221
  • 3
  • 32
  • 80
  • Thank you for the mark up whoever did that ? – csharpdude77 Aug 15 '14 at 10:04
  • If you enter code or a tag, The markup is set automatically. Only if you want specific markup, you can see the help: http://stackoverflow.com/editing-help#syntax-highlighting – LockTar Aug 15 '14 at 10:29

1 Answers1

2

One way is to append a parameter to the URL:

url + "&name=" + param;
Inspector Squirrel
  • 2,537
  • 2
  • 25
  • 38
  • im asking for a solution within the browser url so can test it not code behind thanks – csharpdude77 Aug 15 '14 at 10:35
  • That is in the URL. Add `&name=whateverParameterYouWantHere` to the end of your URL. I did it in code format for clarity .. haha – Inspector Squirrel Aug 15 '14 at 10:38
  • is it cause the way im doing the method, cause i removed the other gets left that one their and its still saying not found does a get have to return a string i thought it could just reutrn an object? – csharpdude77 Aug 15 '14 at 10:43
  • You probably want to return a JSON object, so you're doing it right. If you are receiving an error when trying to use your Get method you may want to take a look at your routes. – Inspector Squirrel Aug 15 '14 at 10:51
  • Are you testing your API using Postman? If not, you may want to take a look at it. – Inspector Squirrel Aug 15 '14 at 10:52
  • my routes are just the default routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } is their something i need to do to add in my WebPortal Controller? – csharpdude77 Aug 15 '14 at 10:52
  • Well, your URLs don't correspond to that route, so you would need to amend that. – Inspector Squirrel Aug 15 '14 at 10:56
  • api/WebPortal/Get/System.WorkItem.Incident doesn't look like controller/action/id to me :) – Inspector Squirrel Aug 15 '14 at 10:57
  • That is what I was asking slippy? what is the correct way to pass that the string for that method. – csharpdude77 Aug 15 '14 at 11:05
  • You might need to ask another question on routing, the last time I made an API I dealt with all the routing by splitting the request URL in my code and doing it that way, so I wouldn't be the best person to ask. – Inspector Squirrel Aug 15 '14 at 11:08
  • just trying to slippy still have the 90 min rule hate that on a new account – csharpdude77 Aug 15 '14 at 11:13
  • ASKED THE question here http://stackoverflow.com/questions/25325631/web-api-routing-understanding – csharpdude77 Aug 15 '14 at 11:27