I have a MVC2 web application in which i have a view containing a simple form as follows:
<%using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { enctype = "multipart/form-data", @id = "frmAddNewObservationPhoto" }))
{%>
<%= Html.AntiForgeryToken()%>
<strong>1. Enter Photo Description</strong><br />
<%= Html.TextArea("photoDescription", Model.photoDescription, new { @style = "height: 100px", @id = "photoDescription" })%><br />
<strong>
2. Browse New Photo:<br />
<%= Html.HiddenFor(x => x.questionNo)%>
<%= Html.HiddenFor(x => x.observationID)%>
<input id="file" type="file" name="file">
<a class="resolveTask" href="javascript:AddNewObservationPhoto()"></a><br />
Or Select Saved Photo: <br />
</strong>
<br />
<%} %>
I have tested on desktop browsers (firefox, IE, Chrome) and the the file the user selects is posted to my action correctly. My action code begins as follows:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult AddNewObservationPhoto(Guid observationID, string photoDescription, decimal questionNo)
{
TaskFireObservations fireObservation = FireHelper.GetObservationByID(observationID, _session);
if (Request.Files.Count > 0)
{
For completion the javascript is as follows:
function AddNewObservationPhoto() {
var photoDescription = $('#photoDescription').val();
if (photoDescription.length == 0) {
alert('Please enter the photo description');
}
else {
$('#frmAddNewObservationPhoto').submit();
}
};
My problem is that when i test this on an iPad version 6.0.1 (hence mobile safari browser), there are no files posted to the action. I have tested on the chrome browser for the ipad and it works fine on there. Ive also tested on an online ipad emulator and it works; i.e. the selected file is posted to the action and then saved to the relevant location.
Does anyone know why this would be happening? I hope ive explained the issue clearly enough.
Thanks.
I am putting this down to a bug in mobile safari as this happens intermittently, i.e. on some occasions the file is posted and on others it does nothing.