zoukankan      html  css  js  c++  java
  • webApi之FromUri和FromBody区别

    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 { getset; }
     
         public string SelectedItemId { getset; }
         public IEnumerable<SelectListItem> Items { getset; }
     }

      

     这里的FromUri强制从url中读取FileRequest 对象,也就是说

        当访问Http://localhost:80?name=eric&SelectedItemId={Guid.NewGuid()}

       此处将自动转换Uri中的参数作为对象属性忽略form传递的数据

    而使用FromBody将强制从FormData中读取数据

    而非URL中获取参数~

  • 相关阅读:
    VMware vSphere企业运维实战
    Unity 3D和2D手机游戏开发
    电商店铺装修推广教程
    uiiamgeview 设置圆角
    cgcolor regcolor tttatribute.
    谈待遇,
    不会自己 加的,也不会自己连线,
    代理,其他的类可以实现,而这个类不能实现,
    代理,
    TTTattribute 缺少 coretext
  • 原文地址:https://www.cnblogs.com/Jeely/p/10958807.html
Copyright © 2011-2022 走看看