LoginSignup
1
0

More than 5 years have passed since last update.

アップロードしたファイルを保存する

Posted at
index.cshtml
<h2>ファイルアップロードのサンプル</h2>

@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <input type="file" name="uploadFile" />
    <input type="submit" />
}
HomeController
using System.Web;
using System.Web.Mvc;

namespace WebApplication4.Controllers
{
    public class HomeController : Controller
    {
        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(HttpPostedFileWrapper uploadFile)
        {
            if (uploadFile != null && uploadFile.ContentLength != 0)
            {
                uploadFile.SaveAs(Server.MapPath("~/uploads/") + uploadFile.FileName);
            }

            return View();
        }
    }
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0