我正在开发带有属性路由的 ASP.NET Web API 2。我有一个控制器类和两个动作方法:[RoutePrefix("api/settings")] public class SettingsController : ApiController { [Route("{getVersion}")] public async Task<IHttpActionResult> GetDBVersion(string PlatformID) { try { JavaScriptSerializer serializer = new JavaScriptSerializer(); SqlManager sqlManager = new SqlManager(); DataTable dt = sqlManager.GetLocalDBVersion(PlatformID); List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); Dictionary<string, object> row; foreach (DataRow dr in dt.Rows) { row = new Dictionary<string, object>(); foreach (DataColumn col in dt.Columns) { row.Add(col.ColumnName, dr[col]); } rows.Add(row); } return Ok(serializer.Serialize(rows)); } catch (Exception ex) { return Content(HttpStatusCode.ExpectationFailed, ex.Message); } } [Route("getBookingSetting/{PlatformID:int}")] public async Task<IHttpActionResult> GetDBBookingSetting(int PlatformID) { try { JavaScriptSerializer serializer = new JavaScriptSerializer(); SqlManager sqlManager = new SqlManager(); DataTable dt = sqlManager.GetBookingSetting(PlatformID.ToString()); List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); Dictionary<string, object> row;我正在通过 url 调用第一个操作方法:/api/settings/getVersion?PlatformID=1第二个是:/api/settings/getBookingSetting?PlatformID=1但是在这两种情况下,每次都会调用第一个操作方法。我如何在方法名称不同但参数具有相同名称和类型(或不同类型)的情况之间路由?
1 回答
- 1 回答
- 0 关注
- 143 浏览
添加回答
举报
0/150
提交
取消