public int AddGoodsInfo(string obj) { Models.GoodsInfo m = JsonConvert.DeserializeObject <Models.GoodsInfo>(obj); //上传图片 if (Request.Form.Files.Count > 0) { // tp://localhost:49233/Files/%E6%96%B0%E5%BB%BA%E6%96%87%E6%9C%AC%E6%96%87%E6%A1%A3.html //获取物理路径 webtootpath string path = hosting.WebRootPath + "\\Img\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var file = Request.Form.Files[0]; //拼接路径 path += $"{file.FileName}"; using (FileStream stream = new FileStream(path, FileMode.Create)) { file.CopyToAsync(stream); } m.GoodsImg = "/Img/" + file.FileName; } return(goodsBLL.AddGoodsInfo(m)); }