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中讀取數據

而非URL中獲取參數~
