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).

2
  • OK. What have you tried? Commented Jul 22, 2014 at 7:17
  • i have tried googling various websites but nothing useful Commented Jul 22, 2014 at 7:26

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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
}

2 Comments

i would like to implement the image uploading as a part of my create view
You might missing something.Read this thread : stackoverflow.com/questions/304617/… . may help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.