ASP MVC Remove Validation

Berikut contoh penggunaan remove validation pada model di ASP MVC. Remove validation hanya berfungsi jika fungsi client side validation diaktifkan.

[code language=”csharp”]
[Remote("CheckForUniqueEmail", "Membership", "SecurityGuard", AdditionalFields="User.UserName", ErrorMessage = "This {0} is already used.")]
public string Email { get; set; }
[/code]

[code language=”html”]
<div class="form-group">
@Html.LabelFor(model => model.Email, new { @class = "col-xs-2 control-label" })
<div class="col-xs-4">
@Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Email)
</div>
</div>
[/code]

Cara mengaktifkan client side validation

[code language=”html”]
<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>
[/code]

Chandra Oemaryadi has written 244 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>