在MVC中的功能化编辑(ASP.NET)

源地址:

http://forums.asp.net/t/1933437.aspx?edit+functionality+in+MVC

下面这段代码能被很好的执行(多个图片),但是当我编辑没有上传任何图片的时候,按下确定键打算更新,更新功能是无效的。


if (MultipleFiles != null)
{}

Error i am getting:Object reference not set to an instance of an object.

[HttpPost]
public ActionResult Edit(int id, Product collection, HttpPostedFileBase[] MultipleFiles)
{
Product p = db.Products.Single(e => e.TagID == id);
List<string> blobs = new List<string>();

if (MultipleFiles != null)
{
foreach (var fileBase in MultipleFiles)
{
if (fileBase != null && fileBase.ContentLength > 0)
{
//检索容器的引用
CloudBlobContainer blobContainer = _myBlobStorageService.GetCloudBlobContainer();
CloudBlob blob = blobContainer.GetBlobReference(fileBase.FileName);

// Create or overwrite the "myblob" blob with contents from a local file 
// 从本地文件创建或覆盖 “myblob”附带内容的对象
blob.UploadFromStream(fileBase.InputStream);}CloudBlobContainer blobContainer1 = _myBlobStorageService.GetCloudBlobContainer();CloudBlob blob1 = blobContainer1.GetBlobReference(fileBase.FileName);blobs.Add(blob1.Uri.ToString());}p.Image = blobs.ElementAt(0).ToString();p.Image1 = blobs.ElementAt(1).ToString();} // TODO: Add update logic herep.Name = collection.Name;p.Price = collection.Price;p.Description = collection.Description;//p.Image = collection.Image;// p.Image1 = collection.Image1;db.SubmitChanges();return RedirectToAction("Index");}



解决方案:

1.在不编辑任何数据的情况下:

在MVC中的功能化编辑(ASP.NET)_第1张图片

2.在编辑单张图片时




   

你可能感兴趣的:(mvc,asp.net)