i am doing my project in asp.net MVC4 using c#
I am trying to select a photo and save that image in a folder,
for that i have an html Begin form
@using (Html.BeginForm("ImageReplace", "Member", new { imgid = @Model.Id }, FormMethod.Post,new { enctype = "multipart/form-data" }))
{
<input type="text" name="fake_section" class="fake_section"><button class="fake_section">Choose Photo</button>
<input type="file" style="display:none;" name="file" id="file" value="Choose Photo" accept="image/png,image/jpeg" />
<input type="submit" name="submit" value="Submit" />
}
And i have a controller also
public ActionResult ImageReplace(HttpPostedFileBase file,int imgid)
{
......
}
For styling and validating the form (only select the gif and jpeg files) i use the following jquery
$('.fake_section').click(function (e) {
e.preventDefault();
$('#file').trigger('click');
});
$('#file').change(function (e) {
var filename = $(this).val();
var ext = filename.split('.').pop().toLowerCase();
if ($.inArray(ext, ['gif', 'jpg', 'jpeg']) == -1) {
alert('not valid!');
}
else {
$('input[name="fake_section"]').val(filename);
}
});

My problem is that when click to choose the photo it is directly go to Controller Action without selecting photo
<input type="button" class="fake_section" value="Choose Photo"/>help?not selecting the imagedo you mean file chooser dialog is not opening?$('#file').click();