Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 829
  • Last Modified:

ASP.NET Web API or MVC routing

Hi,

I am new to both MVC and ASP.NET Web API.  I now have created a Web API project and everything is moving nicely except routing.  I am used to writing web services where I name my methods as I like and they called easily by clients.  Now I have a controller with

GetAllCustomers();

I need to add a

GetCustomersForShop(string key, int shopId);

But it keeps mapped to the GetAllCustomers(); method
http://xyz.com/Customer?key=abcd&shopId=2

I have not changed my routing in the web api config as I don't understand how that works.  Can anyone help please

Cheers
H
0
gbzhhu
Asked:
gbzhhu
1 Solution
 
PaulHewsCommented:
Generally the convention is [controller]/[action]?[parameterstring]

So in your case, if your controller is called CustomerController.cs and you want to access the GetCustomersForShop(string key, int shopId); method, then you need the URL:

http://xyz.com/Customer/GetCustomersForShop?key=abcd&shopId=2
0
 
gbzhhuAuthor Commented:
Thank you.  That sorted it
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now