How i can validate file type??. The following error throw an exception “theFileElement is not found”
@using (Html.BeginForm("Index", "Data", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="FileUpload" />
<input type="submit" name="Submit" id="btnSubmit" value="Upload"/>
}
<script type="text/javascript">
$('#btnSubmit').click(function (e){
filename = theFileElement.value;
if (!/\.csv$/i.test(filename)) {
alert("Please upload csv file only");
return false;
}
return true;
});
</script>
theFileElement is not defined anywhere.
add
before
Also edit your file input to look like