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 ?