I’m triying to make work remote validation in ASP MVC3. I spended some hours reading and trying it, but i didn’t achieve it.
First of all … I’ve added this lines to appSettings in Web.config file
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
Then, I make a class with dataanotations.
Public Class PackageCreationInfo
'Lot of Properties here...
<DisplayName("Id Modalidad")>
<Remote("ModeExists", "PreactivatedLicenses", AdditionalFields:="IdVersion")>
Public Property IdMode As Integer
<Required(ErrorMessage:="La Versión es obligatoria")>
<DisplayName("Id Versión")>
Public Property IdVersion As Integer
End Class
In my view I added this scripts
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
And I’ve this ones in my _layout
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.datepick-es.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Plugins/Expander/expand.js")" type="text/javascript"></script>
Then, In my controller, I’ve this function
Public Function ModeExists(ByVal IdMode As Integer, IdVersion As Integer) As JsonResult
Dim ExistModeForThisVersion As Boolean = _ProductApps.ExistModeForVersion(IdMode, 13)
If (ExistModeForThisVersion) Then
Return Json(String.Format("Esta modalidad no está disponible en la versión seleccionada."), JsonRequestBehavior.AllowGet)
Else
Return Json(True, JsonRequestBehavior.AllowGet)
End If
End Function
My problem is that I can’t get this function called.
The facts is that the generated HTML don’t have a data-val-remote attribute or something like it.
Other client validations that are not “remote” are working propertly.
What could be the problem?
Thanks.
Sorry… I made a stupid mistake (another one)
I will write here my mistake as a penitence because there is remote posibility that It helps to someone.
In my View… I wrote
But It should be
It’s important that the name of the field match the name of the property. Otherways nothing will happens.