3

I'm facing a problem when browsing my website with a tablet (asp.net MVC 2 and browser is mobile safari or the android one). When submitting a form, my model isn't binded and I get some errors. This only happens with a tablet (I tried iPad and ACER iconia tab A200).

Here is my model :

public class ChoixVehiculeImmatriculationModel : Model
{
    [Required(ErrorMessageResourceName = "ImmatriculationRequise", ErrorMessageResourceType = typeof(Erreurs))]
    public string Immatriculation { get; set; }
}

Here is my view :

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ChoixVehiculeImmatriculationModel>" %>

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        <div id="immatriculation">
            <% Html.BeginForm("ChoixImmatriculation", "ChoixVehicule", FormMethod.Post );  %>

            <table id="tabImmatriculation">    
                <tr><td><%= Libelles.SaisissezNumeroImmatriculation %> :</td></tr>
                <tr><td><%= Html.TextBoxFor(m => m.Immatriculation, new { maxlength = 20, autocomplete = "off" })%></td></tr>
                <tr><td>
                    <div id="btnValider">
                        <div class="btnValidText" onclick="$(this).closest('form').submit();"><%= Libelles.Valider %></div>
                    </div>
                </td></tr>
            </table>

            <%Html.EndForm(); %>
        </div>

    </asp:Content>

Here is the controller :

[AcceptVerbs(HttpVerbs.Post)]
    public ActionResult ChoixImmatriculation(ChoixVehiculeImmatriculationModel model)
    {
        if ( ModelState.IsValid )
        {
            using ( IVehiculeUIService vehiculeService = GlobalContainer.Resolve<IVehiculeUIService>() )
            {
                List<VehiculeModel> vehicules = vehiculeService.GetListeVehiculesParImmatriculation(model.Immatriculation);

                return GestionRetourSelonResultats(vehicules);
            }
        }

        return View("ChoixVehiculeImmat", model);
    }

The ModelState.IsValid is false and it says that the field Immatriculation is null. But the textbox has been filled !

It happens randomly at start. I have to do it like 5 times for it to work sometimes.. On my laptop, it never happens, everything is working nice..

Can anyone help me please ? Maybe a difference between browsers and mobile browsers ?

Liam
  • 27,717
  • 28
  • 128
  • 190
  • Have you tried an actual submit button rather than that div with javascript? Since you're creating a form right there, the submit button will act on that. Also, you aren't nesting forms, are you (eg. one in the layout/masterpage file) – Joshua Apr 30 '13 at 13:39
  • Can you check that the textbox does NOT have the same id: `immatriculation` as the surrounding div? Just a way code is generated in the HtmlHelpers... – Tallmaris Apr 30 '13 at 13:53
  • I just tried with a submit button, same issue. – renaud.picavet Apr 30 '13 at 13:54
  • No nesting forms, I just checked. thx. – renaud.picavet Apr 30 '13 at 14:00
  • @Tallmaris : they have the same id.. I just changed the id of the div but I still have the problem. – renaud.picavet Apr 30 '13 at 14:02
  • Maybe it's related to the problem I ran into in this [question](http://stackoverflow.com/questions/12804493/safari-on-ipad-occasionally-doesnt-recognize-asp-net-postback-links)? I wasn't working with ASP.NET MVC, but the underlying problem (ASP.NET not recognizing Safari as being javascript-capable) is causing your issue? – Derek Apr 30 '13 at 15:16
  • @Derek : On the iPad, the issue is occurring both on safari and on an app named Kiosk Pro. They are both recognized as the following : `Version/5.1 Mobile/9B176 Safari/7534.48.3 `or `Version/6.0 Mobile/10B329 Safari/8536.25` so it's seems to be OK on that side, thanks – renaud.picavet Apr 30 '13 at 15:37
  • 1
    It seems that the app I'm using is Safari-based.. I installed Chrome on the iPad and there is no more problem. Weird, mobile Safari can't handle POST ? Javascript problem or something ? – renaud.picavet May 02 '13 at 16:20
  • 1
    Safari and Chrome are both WebKit.... They should essentially render the page the same. – Chris Woolum May 17 '13 at 15:41

1 Answers1

0

Given it happens randomly and doesn't happen in Chrome (which uses exactly the same rendering engine on the iPad as Safari) it is obviously a race condition.

Is the HTML displayed in the browser HTML valid? Perhaps there is a problem there?

meh-uk
  • 2,031
  • 1
  • 23
  • 36