Thursday, March 1, 2012

How to validate a form without Model validation setting in ASP.NET MVC3?

Use jQuery validation plugin directly
<script src="@Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Get, new { id="FormName"}))
{
   <text>Required Field:</text>
    Write(Html.TextBox("id", "", new {@class = "required" }));
    <input type="submit" value="Go" />
}
<script type="text/javascript">
    $(document).ready(function () {
        $("#FormName").validate();
    });
</script>






No comments:

Post a Comment