亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

基于可選參數的訪問控制器

基于可選參數的訪問控制器

C#
白板的微信 2023-09-09 16:21:30
我有一個現有的 WebAPI 控制器方法。 [SwaggerDefaultResponse] [HttpGet, Route("{id:int}", Name = "GetDataId")] public IHttpActionResult Get(long id)  {       //This method returns a full Data  }我必須編寫精細的 WebAPI。我們計劃有一條如下所示的路線:/V1/MYdATA/{DataId}?DataBasic=true如果DataBasic=true 那么我應該調用一個新方法來獲取“基本數據”---并且如果DataBasic=false那么應該返回我現有的完整數據,即應該調用現有方法。我可以了解如何在代碼中實現這一點嗎?
查看完整描述

1 回答

?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

同一控制器


public IHttpActionResult Get(long id, bool DataBasic)

    if (!DataBasic)

    {

        //This method returns a full Data

    }

    else

    {

       //Method Retrieving new data

    }

}

不同的控制器


@using (Html.BeginForm(model.Databasic ? "GetNew" : "GetFull", "ControllerName", new {id = model.Id}))

{

        <input type="submit" name="Get" />

}



public IHttpActionResult GetNew(long? id)


    //Method Retrieving new data


}


public IHttpActionResult GetFull(long id)

    //This method returns a full Data

}


查看完整回答
反對 回復 2023-09-09
  • 1 回答
  • 0 關注
  • 115 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號