better way of showing File Upload Errors?
- by coure06
Model:
public class EmailAttachment
{
public string FileName { get; set; }
public string FileType { get; set; }
public int FileSize { get; set; }
public Stream FileData { get; set; }
}
public class ContactEmail: IDataErrorInfo
{
public string Name { get; set; }
public string Email { get; set; }
public string Message { get; set; }
public EmailAttachment Attachment { get; set; }
public string Error { get { return null; } }
public string this[string propName]
{
get
{
if (propName == "Name" && String.IsNullOrEmpty(Name))
return "Please Enter your Name";
if (propName == "Email"){
if(String.IsNullOrEmpty(Email))
return "Please Provide an Email Address";
else if(!Regex.IsMatch(Email, ".+\\@.+\\..+"))
return "Please Enter a valid email Address";
}
if (propName == "Message" && String.IsNullOrEmpty(Message))
return "Please Enter your Message";
return null;
}
}}
And my controller file
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Con(ContactEmail ce, HttpPostedFileBase file)
{
return View();
}
Now the Problem
From the form i am getting Name,Email, Message and uploaded file. I can get validation errors automatically for Name,Email,Message using public string this[string propName]. How can i show validation errors if Attachment.FileSize 10000? If i write its code in
public string this[string propName]
i alwasy getting Attachment null. How can i fill Attachment Object of ContactEmail so that i can manage all errors on same place?