---
title: "How to Attachments in mvc?"  
description: "How to Attachments in mvc?"  
author: "Anonymous User"  
published: 2014-10-09  
updated: 2014-10-09  
canonical: https://www.mindstick.com/forum/2346/how-to-attachments-in-mvc  
category: "asp.net mvc"  
tags: ["asp.net", "asp.net mvc"]  
reading_time: 1 minute  

---

# How to Attachments in mvc?

I have to [update](https://www.mindstick.com/forum/156353/what-is-hummingbird-update) my [contact form](https://answers.mindstick.com/qa/50721/how-to-delete-a-contact-form-your-iphone-8-plus), to allow attachments.

My [reading](https://www.mindstick.com/articles/126273/books-commonly-found-on-college-reading-lists) indicates I need to add a new [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) to my [model](https://yourviews.mindstick.com/view/81334/america-is-reopening-after-corona-lockdown-but-on-swedish-model), of type HttpPostedFileBase

So, I did the following

```
@model Ui.Models.Email     @using (Html.BeginForm())    {        @Html.ValidationSummary(true)         @Html.TextBoxFor(a => a.Attachment, new { @type = "file" })    }
```

And my model\

```
public class Email        {            [Display(Name = "Attach away my assuming chum")]            public HttpPostedFileBase Attachment { get; set; }        }
```

The [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) I'm getting is the property is always [null](https://www.mindstick.com/forum/33922/how-to-use-null-coalescing-operator-in-c-sharp)!

Usually, when it's a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp), int or List, the [binding](https://www.mindstick.com/blog/146/dynamic-binding-in-c-sharp) works, but I have no idea how to get it to bind to my model.

## Replies

### Reply by Anonymous User

To allow your [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) to upload files, it should have the enctype="multipart/form-data" attribute.

**You can do it like so.**

```
@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new{ enctype="multipart/form-data" })){    @Html.ValidationSummary(true)     @Html.TextBoxFor(a => a.Attachment, new { @type = "file" })}
```


---

Original Source: https://www.mindstick.com/forum/2346/how-to-attachments-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
