Within my MVC 4 application when a user registers I'm looking to give them the option to select an image and upload that at the same time as registering - I was just looking at some guidance as to how to do this.
Here is my MVC Model for registering - I've added HttpPostedFileBase to hold the file being posted along with the username and password for new account being registered:
public class RegisterModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
public HttpPostedFileBase File { get; set; }
}
The registration View includes the following input html:
<input id="register-avatar" type="file" name="file" />
However when I register, the value for the file is always null...
UPDATE 04-11-2013
I finally created a post which doesn't seem to be covered on how to include a profile image upload with the generic RegisterModel within the MVC 4 Template. You can find it here - MVC 4 Add Profile Image to RegisterModel
UPDATE
The problem as mentioned in the comment below is that I did not have the enctype set. For more information have a look here