Getting Started with Adobe After Effects - Part 6: Motion Blur

Upload Image Close it
Select File

I am Jalpesh Vadgama a Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having more then 6 years of experience in .NET Technology.
Browse by Tags · View All
BRH 79
#.NET 52
C#.NET 48
ASP.NET 4.0 31
VisualStudio 27

Archive · View All
December 2010 16
July 2011 13
April 2011 13
April 2012 12
January 2011 12
June 2011 11
May 2011 11
May 2012 8
February 2013 7
January 2013 7

File Upload in ASP.NET MVC3

Apr 20 2012 3:55AM by Jalpesh   

If you are a web developer you often need to upload file on the web server or database. In today’s post I am going explain how we can upload file in ASP.NET MVC 3 with razor syntax.

So, first thing we need to create a view that will contain the file upload control. I am going to use an existing mvc template for this demo. So I have just modified the default Index view like following.

    ViewBag.Title = "Home Page";
    To learn more about ASP.NET MVC visit <a href="" title="ASP.NET MVC Website"></a>.
    @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
        <label for="file">Upload Image:</label>
        <input type="file" name="file" id="file"/>
        <input type="submit" value="Upload Image" />

Here you can see that I have used Html.Begin form to create a form with multipart as we all know this attribute is required to have to upload any kind of file to the server. Also I have used the simple HTML file control and a submit button to submit a form. Now we are done with HTML so it’s time to write server-side code.

Following is a code for that.

       public ActionResult Index(HttpPostedFileBase file)
           string path = System.IO.Path.Combine(Server.MapPath("~/Images"), System.IO.Path.GetFileName(file.FileName));
           ViewBag.Message = "File uploaded successfully";
           return View();

As you can see I have create a new ActionResult Index with parameter and I have given HttpPost attribute to it to get all data from post method of form we are submitting and then I have written a code to save file in Images folder.

That’s it. We are dong with coding now its time to run the application. Once you press F5 it will look into the browser like following.

How to upload file in mvc3 

Now once you select file and click on upload image it will upload files and give a message like following.

File Upload in ASP.NET MVC 3

We are done. Hope you like it. Stay tuned for more updates. Till then Happy programming.

Shout it

Tags: ASP.NET, ASP.NET MVC, FileUpload,

15 · 11% · 3548
3 Readers Liked this
Guru Samy Liked this on 4/21/2012 5:14:00 AM
Profile · Blog
Jacob Sebastian Liked this on 4/21/2012 5:38:00 AM
Profile · Blog · Facebook · Twitter
Manas Ranjan Dash Liked this on 4/21/2012 7:30:00 AM
Profile · Blog · Facebook · Twitter


Your Comment

Sign Up or Login to post a comment.

"File Upload in ASP.NET MVC3" rated 5 out of 5 by 3 readers
File Upload in ASP.NET MVC3 , 5.0 out of 5 based on 3 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]