Asp.Net网页API多个get方法 [英] Asp.Net Web Api multiple get methods

查看:116
本文介绍了Asp.Net网页API多个get方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到有多个get方法apicontroller路由配置。

I am trying to find the routing configuration for apicontroller having multiple get methods.

控制器类有3种方法:

Public Function GetAllProducts() As IEnumerable(Of Product)
Public Function GetProductById(prodid As Integer) As Product
Public Function GetProductByCategory(categoryName As String) As Product

请说明需要的所有3种方法的路由配置。

Please suggest the routing configuration needed for all the 3 methods.

推荐答案

我假设一个类别可能返回若干个产品。

I assume that a category may return several products.

在VB中使用可选的参数,如:

In VB use optional parameters like:

Public Function GetProducts(Optional category As String = "") As IEnumerable(Of Product)
Public Function GetProduct(ByVal id as Integer) As Product

或C#

public IEnumerable<Product> GetProducts(string category = "")
public Product GetProduct(int id)

使用URL's这样的:

Use URL´s like:

/api/product
/api/product/1
/api/product?category=myCategory

留在地方的默认路由。

Leave the default route in place.

这篇关于Asp.Net网页API多个get方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆