Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<label class="" for="form-last-name">@Resources.Registration.FirstName*</label>
@Html.TextBoxFor(model => model.FirstName)




<label class="" for="form-email">@Resources.Registration.LastName*</label>
@Html.TextBoxFor(model => model.LastName)



<label class="" for="form-email">@Resources.Registration.Address*</label>
@Html.TextBoxFor(model => model.Address)



<button type="submit" class="btn" >Submit</button>

<script type="text/javascript>
function PageValidate() {
if ($('#FirstName').val() == '' || $('#FirstName').val() == null) {
$("#firstName").html('First name is required');
$('#FirstName').focus();
return false;
}
else {
$("#firstName").html('');
}

if ($('#LastName').val() == '' || $('#LastName').val() == null) {

$("#lastName").html('Last name is required');
$('#LastName').focus();
return false;
}
else {
$("#lastName").html('');
}

if ($('#Address').val() == null || $('#Address').val() == '') {
$("#addresses").html('Address is required');
$('#AddressLine1').focus();
return false;
}
else {
$("#addresses").html('');
}

}
</script>

What I have tried:

In view page-

@Resources.Registration.FirstName is working but,
In javascript error message are not working-:
$("#firstName").html('@Resources.Registration.errorFirstName');

Please solve this problem
Posted
Updated 27-Jun-16 0:57am
v2
Comments
Marcus Kramer 27-Jun-16 13:05pm    
You cannot read a server variable/value from the client without hitting the server. If you are using MVC, why are you not using default MVC model validation?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900