Created
April 6, 2016 14:39
-
-
Save rionmonster/40890d53ad857a57afb4836635f7d898 to your computer and use it in GitHub Desktop.
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
public class HomeController : Controller | |
{ | |
[HttpGet] | |
public ActionResult Index() | |
{ | |
return View(); | |
} | |
[HttpPost] | |
public ActionResult Index(HttpPostedFileBase file) | |
{ | |
if (file == null) | |
{ | |
return Content("File was null."); | |
} | |
return Content($"File name is {file.FileName}."); | |
} | |
} |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>File Testing</title> | |
</head> | |
<body> | |
<h2>AJAX Form</h2> | |
@using (Ajax.BeginForm("Index", "Home", new AjaxOptions() | |
{ | |
HttpMethod = "Post", | |
InsertionMode = InsertionMode.Replace, | |
}, new { enctype = "multipart/form-data" })) | |
{ | |
<input name='file' type='file' /> | |
<input type='submit'> | |
} | |
<h2>Normal Form</h2> | |
@using (Html.BeginForm("Index", "Home",FormMethod.Post, new { enctype = "multipart/form-data" })) | |
{ | |
<input name='file' type='file' /> | |
<input type='submit'> | |
} | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment