Tuesday, 10 September 2013

how to insert client-side validation ajax onSuccess function mvc 4

how to insert client-side validation ajax onSuccess function mvc 4

I have a problem with unobtrusive validation after an ajax.ActionLink, the
form submits correctly and when ajax replace div target, not creates the
client-side validation.
I have this in the view:
@using (Ajax.BeginForm("Action", "Controller", new { area = "Area" }, new
AjaxOptions { HttpMethod = "post", InsertionMode = InsertionMode.Replace,
UpdateTargetId = "divTarget" }))
{
//html stuff....
<li>
<label><br/></label>
<div class="perfil_datos_botones">
<input type="submit" value="Crear cita" id="enviar">
@Ajax.ActionLink("Volver", "Action", "Controller", new
{ area = "Area" }, new AjaxOptions { HttpMethod =
"get", InsertionMode = InsertionMode.Replace,
UpdateTargetId = "divTarget", OnComplete =
"ValidarForm('target')" }, new { @class =
"links_botones" })
</div>
</li>
</ul>
}
The OnComplete function:
function ValidarForm(sel) {
var selector = "#" + new String(sel);
$.validator.unobtrusive.parse(selector);
}
I put this on the view:
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")"
type="text/javascript"></script>
and this in the Layout:
@Scripts.Render("~/bundles/jqueryval_noajax")
this bundle renders jquery-validation plugin without ajax.unobtrusive.js
because this generates multiple post on the view
I have tried to use the function in OnSuccess and either works, the
validator throws an exception that says: "unobtrusive field is undefined".
I need to reload the client-side validation on every partialView that uses
ajax.BeginForm or ajax.ActionLink

No comments:

Post a Comment