0

私は mvc の初心者で、mvc4 アプリケーションを使用しています。サーバー パスにアップロードされたマシンの画像を表示したいです。

public partial class Picture
{
    public Picture()
    {
        this.Approvments = new HashSet<Approvment>();
    }

    public int PicId { get; set; }
    public string PicPath { get; set; }
    public Nullable<bool> Status { get; set; }
    public Nullable<System.DateTime> PickDate { get; set; }
    public Nullable<int> UserId { get; set; }
    public Nullable<int> ApproveId { get; set; }
    public Nullable<int> MacId { get; set; }

    public virtual ICollection<Approvment> Approvments { get; set; }
    public virtual Machine Machine { get; set; }
    public virtual User User { get; set; }
}

}

これは、特定のパスにアップロードするためのコントローラーにあります

 public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
    {
        foreach (var file in files)
        {
            if (file.ContentLength > 0)
            {
                string name = Guid.NewGuid().ToString().Replace("-", "");
                var fileName = Path.GetFileName(file.FileName+name);
                var path = Path.Combine(Server.MapPath("~/App_Data/upload"), fileName);
                file.SaveAs(path);
            }
        }
        return RedirectToAction("Index");
    }

画像を表示するだけでどこに行けばいいのかわからない??

4

2 に答える 2

1

あなたのController

    public ActionResult DisplayPic()
    {
      Picture picture = new Picture();
      picture.PicPath = GetImagePath();  //Logic to get the image path as string
      return View(picture);
     }

あなたのView

@model YourNameSpace.Model.Picture

<img src= "@Url.Content(Model.PicPath)" alt="Image"/>

コードをチェックしませんでしたが、これで問題ありません..! それが役立つかどうか教えてください

于 2013-11-05T12:55:52.637 に答える