---
title: "upload files in asp.net mvc"  
description: "upload files in asp.net mvc"  
author: "Anonymous User"  
published: 2013-05-13  
updated: 2013-05-13  
canonical: https://www.mindstick.com/forum/873/upload-files-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 1 minute  

---

# upload files in asp.net mvc

Hi Expert!\
How to upload [file in ASP.NET](https://www.mindstick.com/forum/158972/how-to-read-appsettings-values-from-a-json-file-in-asp-dot-net-core) MVC 4. I'm try as following line of code. but it returns always [null value](https://www.mindstick.com/forum/23045/document-body-appendchild-has-a-null-value). \
.cshtml\
<input type="file" name="file" id="file" />controller.cs\
[HttpPost] public [ActionResult](https://www.mindstick.com/forum/33961/what-is-the-difference-between-actionresult-and-viewresult) Index(BookModel model, HttpPostedFileBase file, FormCollection values) { try { if (![ModelState.IsValid](https://www.mindstick.com/forum/2002/modelstate-isvalid-contains-errors-when-using-mongodb)) { return View("Index", new BookModel()); }\
if (file != null && file.ContentLength > 0) { var [fileName](https://www.mindstick.com/interview/23463/difference-between-include-filename-and-include-filename) = Path.GetFileName(file.FileName); var path = [Path.Combine](https://www.mindstick.com/forum/161589/how-can-you-use-path-combine-and-path-getextension-when-working-with-file-paths)([Server.MapPath](https://www.mindstick.com/forum/2132/server-mappath-in-asp-dot-net)("~/img/"), fileName); file.SaveAs(path);\
model.ImageUrl = fileName; }\
\
//SendMail(); } catch ([Exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling) ex) { return View("Index", new BookModel()); }\
return View("Success"); }\
Please help me. Thanks in advance!

## Replies

### Reply by AVADHESH PATEL

Hi Ezra!\
For upload files in [asp.net MVC](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc) add form in you application as following.\
enctype="multipart/form-data"


---

Original Source: https://www.mindstick.com/forum/873/upload-files-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
