Created
July 18, 2014 17:31
-
-
Save nakaji/779b3f68e6aeaa2c07d0 to your computer and use it in GitHub Desktop.
アップロードしたファイルを保存する ref: http://qiita.com/nakaji/items/f19a957b3b214bc96982
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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