第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ASP.NET Web API中具有多個GET方法的單個控制器

ASP.NET Web API中具有多個GET方法的單個控制器

C#
肥皂起泡泡 2019-10-23 14:32:02
在Web API中,我有一類類似的結(jié)構(gòu):public class SomeController : ApiController{    [WebGet(UriTemplate = "{itemSource}/Items")]    public SomeValue GetItems(CustomParam parameter) { ... }    [WebGet(UriTemplate = "{itemSource}/Items/{parent}")]    public SomeValue GetChildItems(CustomParam parameter, SomeObject parent) { ... }}由于我們可以映射各個方法,因此在正確的位置獲得正確的請求非常簡單。對于只有一個GET方法但也有一個Object參數(shù)的類似類,我成功使用IActionValueBinder。但是,在上述情況下,出現(xiàn)以下錯誤:Multiple actions were found that match the request: SomeValue GetItems(CustomParam parameter) on type SomeTypeSomeValue GetChildItems(CustomParam parameter, SomeObject parent) on type SomeType我試圖通過覆蓋ExecuteAsync方法來解決此問題,ApiController但到目前為止還沒有運氣。關(guān)于這個問題有什么建議嗎?編輯:我忘了提一下,現(xiàn)在我正嘗試在ASP.NET Web API上移動此代碼,而ASP.NET Web API具有不同的路由方法。問題是,如何使代碼在ASP.NET Web API上工作?
查看完整描述

3 回答

?
慕尼黑8549860

TA貢獻1818條經(jīng)驗 獲得超11個贊

從此:


config.Routes.MapHttpRoute("API Default", "api/{controller}/{id}",

            new { id = RouteParameter.Optional });

對此:


config.Routes.MapHttpRoute("API Default", "api/{controller}/{action}/{id}",

            new { id = RouteParameter.Optional });

因此,您現(xiàn)在可以指定要將HTTP請求發(fā)送到的操作(方法)。


發(fā)布到“ http:// localhost:8383 / api / Command / PostCreateUser”會調(diào)用:


public bool PostCreateUser(CreateUserCommand command)

{

    //* ... *//

    return true;

}

并發(fā)布到“ http:// localhost:8383 / api / Command / PostMakeBooking”會調(diào)用:


public bool PostMakeBooking(MakeBookingCommand command)

{

    //* ... *//

    return true;

}

我在自托管的WEB API服務(wù)應(yīng)用程序中嘗試了此方法,它的工作原理很像:)


查看完整回答
反對 回復(fù) 2019-10-23
  • 3 回答
  • 0 關(guān)注
  • 965 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號