Now <%= Html.TextBoxFor(model => model.Name)%> is the key here u should give an ID to each of your elements that you want to use validation on..
so its gonna look like;
<%= Html.TextBoxFor(model => model.Name,new { id="ClientNameTxt"})%>
if you already defined some scripts (.js files) and want to implement to this view then use
<script src="@Url.Content("~/Scripts/yourjsfile.js")" type="text/javascript"></script>
and use ur functions to validate or else write new script
<script type="text/javascript">
$(document).ready(function () {
var frm = $("#formname");
frm.validate();
});
$('#formname').Submit(function (event) {
/* Call ur form with the id you have given */
var f = $("#formname");
if (f.valid()) { /* When the form is valid */
} else { /* When the form is not valid */
event.preventDefault(); /* Prevent from submitting the form */
$("#ClientNameTxt").highlight(); /* Do some validation stuff on ur validation required element */
}
});
</script>
at the end it will look like;
<!--Your form name, Controller name-->
@using (Html.BeginForm("Formname", "ControllerName", FormMethod.Post,new { id="Formname", onkeypress="return event.keyCode != 13;"}))
{
<p>
<label for="ClientName">ClientName:</label> <!--Give an ID to your element-->
<%= Html.TextBoxFor(model => model.Name, new { id="ClientNameTxt" })%>
</p>
}
<script type="text/javascript">
$(document).ready(function () {
var frm = $("#formname");
frm.validate();
});
$('#formname').Submit(function (event) {
/* Call ur form with the id you have given */
var f = $("#formname");
if (f.valid()) { /* When the form is valid */
} else { /* When the form is not valid */
event.preventDefault(); /* Prevent from submitting the form */
$("#ClientNameTxt").highlight(); /* Do some validation stuff on ur validation required element */
$("#Formname").append('<ul><li> Fill the empty areas and try again. <li><ul>');
/* This is the worst i can do. Just to let you understand it easly. */
}
});
</script>
if u still have problems with this issue! i guess ur solution is at training your self with the --> jquery