I am trying to post an image using ASp.NET MVC 3 and Jquery. I have the following code in the view
form action="/profile/upload" method="post" enctype="multipart/form-data">
<label for="photo">Photo:</label>
<input name="photo" id="photo" type="file">
<input value="Upload" type="submit">
</form>
and in the controller
public ActionResult Upload(HttpPostedFileBase photo)
{
string path = @"D:\Temp\";
if(photo != null)
photo.SaveAs(path + photo.FileName);
return RedirectToAction("Index");
}
What I want is I want to upload only jpg or png files through file upload. and I want to do the validations in JQuery.
Please can anyone suggest a simple method and how I can check the validations before submit is fired..
<form action="/profile/upload" method="post" enctype="multipart/form-data">
<label for="photo">Photo:</label>
<input name="photo" id="photo" type="file">
<input value="Upload" type="submit">
</form>