public 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类的定义

   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?name=eric&SelectedItemId={Guid.NewGuid()}

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

 

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

webApi之FromUri和FromBody区别

而非URL中获取参数~

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
猜你喜欢
  • 2021-08-29
  • 2022-12-23
  • 2021-10-30
  • 2022-01-05
相关资源
相似解决方案