Skip to content

Instantly share code, notes, and snippets.

@nakaji
Created July 18, 2014 17:31
Show Gist options
  • Save nakaji/779b3f68e6aeaa2c07d0 to your computer and use it in GitHub Desktop.
Save nakaji/779b3f68e6aeaa2c07d0 to your computer and use it in GitHub Desktop.
アップロードしたファイルを保存する ref: http://qiita.com/nakaji/items/f19a957b3b214bc96982
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();
}
}
}
<h2>ファイルアップロードのサンプル</h2>
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="uploadFile" />
<input type="submit" />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment