Previously I had shown How to...
MVC:
- Forms Authentication in Asp.Net MVC 5
- Cascading DropDowns in Asp.Net MVC
- AngularJS with Web Api in Asp.net MVC using Token based Authentication
- Ajax helper Based Search in MVC
- Customizing Authorize attribute or Role based Authentication or Authorization in MVC
- Display message when user is not authorized in mvc
- How to use AutoMapper
- select option with multiple values
- CRUD operations using Bootstrap Modal in Asp.Net MVC
- Asynchronous Requests for CRUD operations in Asp.Net MVC
Create a Project using Visual Studio. In Index.cshtml file ADD below code.
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<h3>Upload Files</h3>
<br />
<input type="file" name="files" multiple class="btn btn-default" />
<br />
<button type="submit" class="btn btn-primary">Upload</button>
}
In the HomeController.cs file ADD the below code.
[HttpPost]
public ActionResult Index(IEnumerable Files)
{
try
{
foreach (var file in Files)
{
if (file != null && file.ContentLength > 0)
{
file.SaveAs(Path.Combine(Server.MapPath("/uploads/" + file.FileName)));
}
}
}
catch (Exception ex)
{
string Msg = ex.Message;
}
return View();
}
No comments:
Post a Comment