私はmvcに新しく、問題が残っています。私は答えを一掃して見つけられませんでしたが、私は何かが私を飛ばしたと確信しています。問題は、ファイルをApp_Dataフォルダにアップロードした後にファイルにアクセスする方法がわからないことです。私のモデルはファイルをApp_Dataにアップロードした後にファイルを表示する方法/ Razorを使用してMVC 3でアップロードする方法?
public class FileDescription
{
public int FileDescriptionId { get; set; }
public string Name { get; set; }
public string WebPath { get; set; }
public long Size { get; set; }
public DateTime DateCreated { get; set; }
}
である私は、この
public class HomeController : Controller
{
// This action renders the form
public ActionResult Index()
{
return View();
}
// This action handles the form POST and the upload
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
// Verify that the user selected a file
if (file != null && file.ContentLength > 0)
{
// extract only the fielname
var fileName = Path.GetFileName(file.FileName);
// store the file inside ~/App_Data/uploads folder
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
// redirect back to the index action to show the form once again
return RedirectToAction("Index");
}
}
を使用し、私は私のコントローラの場合、この
@using (Html.BeginForm("Index", "Home", FormMethod.Post,
new { enctype="multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="submit" />
}
を使用する私の見解について
:私は、私はすべてのフォーラムで見られるのと同じコードを使用します
問題は、ファイルをデータベースにアップロードしてから、WebPathを自分のファイルへのリンクにすることです。私は自分自身を十分に明確にすることを望む。どんな助けでも本当に感謝しています。 おかげ
私は私のデータベースはファイルではなく、ファイル自体へのパスのみを持っていると思います。 – Robert
「ファイルを見る」という意味を定義したり、リンクとして表示したりするか、ファイルの実際の内容を表示しますか? –