Tuesday, April 3, 2012

Custom JQuery Validation with MVC.Net Ajax.BeginForm

<% using (Ajax.BeginForm("Save", "Setup", new AjaxOptions { OnSuccess = "saveComplete", OnBegin = "validateForm", OnComplete = "ScreenManager.Complete" }, new { id = "setup-edit-form" }))
{%>

<%= Html.Label("Name") %><%= Html.TextBox("Name",Model.Name) %>

<%}% >

<script type="text/javascript">
$(document).ready(function () {
$("#setup-edit-form").validate({
rules: {
Name: "required"
}

});
});

function validateForm()
{
var validated = $('#setup-gateways-edit-form').valid();
if (validated) {
alert('this is validated');
}
return validated;
}
<script>

No comments:

Post a Comment