---
title: "HOW TO UPLOAD IMAGE IN MVC?"  
description: "HOW TO UPLOAD IMAGE IN MVC?"  
author: "Anand Pandey"  
published: 2017-05-15  
updated: 2017-05-15  
canonical: https://www.mindstick.com/forum/34295/how-to-upload-image-in-mvc  
category: "c#"  
tags: ["c#", "mvc"]  
reading_time: 1 minute  

---

# HOW TO UPLOAD IMAGE IN MVC?

Hello, I am having [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) in uploading an [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) through [MVC](https://www.mindstick.com/forum/155803/define-cache-profile-in-mvc) in C#.[Anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) please help me with step by step [Procedure](https://www.mindstick.com/forum/32/stored-procedure-return-datatype) to [upload](https://www.mindstick.com/forum/12860/how-to-upload-file-asynchronously-using-generic-handler) image using [Entity Framework](https://www.mindstick.com/articles/1566/crud-operations-using-entity-framework-code-first-approach).

## Replies

### Reply by Manish Kumar

You can use the same code as described below

Your view code

```
@{    Layout = null;} <!DOCTYPE html> <html><head>    <meta name="viewport" content="width=device-width" />    <title>Upload</title></head><body>    <div>        @using (Html.BeginForm("FileUpload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" })){     <label for="file">Upload Image:</label>    <input type="file" name="file" id="file" style="width: 100%;" />    <input type="submit" value="Upload" class="submit" />}    </div></body></html> 
```

\

your controller should have action method which would accept HttpPostedFileBase

``

```
  public ActionResult FileUpload(HttpPostedFileBase file)        {            if (file != null)            {                string pic = System.IO.Path.GetFileName(file.FileName);                string path = System.IO.Path.Combine(                                      
                 Server.MapPath("~/images/profile"), pic);                // file is uploaded                file.SaveAs(path);                 // save the image path path to the database or you can send image                // directly to database                // in-case if you want to store byte[] ie. for DB                using (MemoryStream ms = new MemoryStream())                {                   
                  file.InputStream.CopyTo(ms);                    byte[] array =ms.GetBuffer();                }             }            // after successfully uploading redirect the user            return RedirectToAction("actionname", "controller name");        } 
```


---

Original Source: https://www.mindstick.com/forum/34295/how-to-upload-image-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
