FromUriとFromBody差のWEBAPI

ublic  Link GetLink([FromUri] FileRequest fileRequest)
    {
        if  (ModelState.IsValid)
        {
            var  xml = WebConfigurationManager.AppSettings[ "appDiscoveryXml" ];
            var  wopiServer = WebConfigurationManager.AppSettings[ "appWopiServer" ];
            bool  updateEnabled =  false ;
            bool .TryParse(WebConfigurationManager.AppSettings[ "updateEnabled" ],  out  updateEnabled);
            WopiAppHelper wopiHelper =  new  WopiAppHelper(HostingEnvironment.MapPath(xml), updateEnabled);
 
            var  result = wopiHelper.GetDocumentLink(wopiServer + fileRequest.name);
 
            var  rv =  new  Link
            {
                Url = result
            };
            return  rv;
        }
 
        throw  new  ApplicationException( "Invalid ModelState" );
    }

 

  クラス定義FileRequest

1
2
3
4
5
6
7
public  class  FileRequest
  {
      public  string  name {  get set ; }
 
      public  string  SelectedItemId {  get set ; }
      public  IEnumerable<SelectListItem> Items {  get set ; }
  }

  

 ここFromUri URLから必須読み取りFileRequestオブジェクト、すなわち

    当访问のHttp:// localhostの:80名=エリック&SelectedItemId = {Guid.NewGuid()}

   オブジェクトのプロパティは、データを無視するように渡され、ここでのパラメータは自動的にウリをフォームに変換され

 

いるFormDataからデータを読み取るために使用FromBody力

URLパラメータを取得するのではなく〜

おすすめ

転載: www.cnblogs.com/Jeely/p/10958807.html