sri*_*sri 6 c# asp.net asp.net-mvc asp.net-mvc-5
在localhost上构建时,上传图像文件的代码工作正常.但是在部署时,它不起作用而且没有任何错误.
我尝试将imagePath更改/Content/Images/Items/为~/Content/Images/Items/和Content/Images/Items/.仍然没有解决方案
[HttpPost]
public ActionResult AddProduct(ProductDisplay productDisplay,HttpPostedFileBase upload)
{
bool isSaved = false;
string fileName = string.Empty;
string imagePath = string.Empty;
try
{
if(upload!=null && upload.ContentLength>0)
{
fileName = System.IO.Path.GetFileName(upload.FileName);
imagePath = "/Content/Images/Items/" + fileName;
upload.SaveAs(Server.MapPath(imagePath));
}
else
imagePath = "/Content/Images/Items/" + "NoImage.jpg";
productDisplay.ImagePath = imagePath;
ProductMangementBL balProduct = new ProductMangementBL();
isSaved = balProduct.AddProduct(productDisplay);
}
catch (Exception ex)
{
isSaved = false;
}
return RedirectToAction("ProductList", new RouteValueDictionary(new { controller = "Product", action = "ProductList", Id = productDisplay.CategoryID }));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3469 次 |
| 最近记录: |