0

I am having a problem uploading images in ASP.NET MVC 3. Currently I have a class called EmployeeModel which has the properties for employees:

public class EmployeeModel       //Model for employee information
{
    [Required(ErrorMessage = "ID Required")]
    public int ID { get; set; }//Employee Id

    [Required(ErrorMessage = "Name Required")]
    [RegularExpression(@"^[a-zA-Z\s]+$", ErrorMessage = "Name can have only alphabets and spaces")]
    public string Name { get; set; }//Employee Name

    [DataType(DataType.Date)]
    public DateTime DOB { get; set; }//Employee Date of birth

    [DataType(DataType.Date)]
    public DateTime DOJ { get; set; }//Employee Date of Joining

    [Required(ErrorMessage = "Address Requried")]
    public string Address { get; set; }//Employee Address

    [Required(ErrorMessage="Mobile Number Requried")]
    [RegularExpression(@"[0-9]{10}", ErrorMessage = "Mobile number not valid")]
    public double Mobile { get; set; }//Employee Mobile number

    [Required(ErrorMessage = "Email Requried")]
    [RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Email Id not  valid")]
    public string Email { get; set; }//Employee Email-ID

    [Required(ErrorMessage = "Designation Requried")]
    public string Designation { get; set; }//Employee Designation

    [Required(ErrorMessage = "Salary Required")]
    public double Salary { get; set; }//Employee Salary        
}

The requirement is that I need to upload an image for each employee and display them. I'm using a text file to store the information of the employee (acting as a database).

Dave Cousineau
  • 12,154
  • 8
  • 64
  • 80

2 Answers2

0

Maybe these articles can help: this and this.

The one from CodeProject uses MongoDB, but I think you can ignore that parts and get what you want. It seems simple enough.

And this one is the most simple one from SO.

Community
  • 1
  • 1
Alireza
  • 4,976
  • 1
  • 23
  • 36
0

Try to use HttpPostedFileBase property in your model. And in your POST action use :

@using (Html.BeginForm("Action_name", "Controler_name", FormMethod.Post, 
                                   new { enctype = "multipart/form-data" }))
{
// your form data here
}
Anupam Singh
  • 1,158
  • 13
  • 25