Created
September 14, 2013 15:33
-
-
Save aliirz/6562961 to your computer and use it in GitHub Desktop.
MVC File Upload Example
This file contains hidden or 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
[Authorize(Roles = "Manager")] | |
public ActionResult Logo() | |
{ | |
return View(); | |
} | |
[Authorize(Roles = "Manager")] | |
[HttpPost] | |
public ActionResult Logo(HttpPostedFileBase file) | |
{ | |
if (file != null && file.ContentLength != 0) | |
{ | |
var fileName = Path.GetFileName(file.FileName); | |
var path = Path.Combine(Server.MapPath("~/Content/Logos"), fileName); | |
file.SaveAs(path); | |
} | |
return RedirectToAction("Settings"); | |
} |
This file contains hidden or 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
@{ | |
ViewBag.Title = "Choose your Logo"; | |
Layout = Url.Content("~/Views/Shared/_SettingsLayout.cshtml"); | |
} | |
<div class="well"> | |
@using (Html.BeginForm("Logo", "Manager", FormMethod.Post, new { enctype = "multipart/form-data", @class = "form-horizontal" })) | |
{ | |
<div class="control-group"> | |
<label class="control-label"> | |
Upload Your company's Logo | |
</label> | |
<div class="controls"> | |
<input type="file" name="file" /> | |
</div> | |
</div> | |
<input type="submit" class="btn btn-info" value="Upload" /> | |
} | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment