I am new to mvc3. I want to develop form validation using Jquery Watermark effect. If any error occurs the textbox border highlight in red color and error validation display in textbox only.
My Model is like this,
public class Registration
{
[Required]
[Display(Name = "Name")]
public string Name { get; set; }
[Required]
[Display(Name = "Email")]
public string Email { get; set; }
[Required]
[Display(Name = "Phone No")]
public string PhoneNo { get; set; }
[Required]
[Display(Name = "City")]
public string City { get; set; }
[Required]
[Display(Name = "Country")]
public string Country { get; set; }
}
My View Page Code is like this
@model WaterMarkFormInput.Models.Registration
<script type="text/javascript">
$(document).ready(function () {
$('#name').Watermark("Your Name");
$('#email').Watermark("Your Email");
$('#phoneno').Watermark("Your PhoneNumber");
$('#city').Watermark("Your City");
$('#country').Watermark("Your Country");
})
</script>
<script src="../../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.watermarkinput.js" type="text/javascript"></script>
<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>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Registration</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Name, new { id="name"})
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Email, new { id = "email" })
@Html.ValidationMessageFor(model => model.Email)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.PhoneNo)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.PhoneNo, new { id = "phoneno" })
@Html.ValidationMessageFor(model => model.PhoneNo)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.City)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.City, new { id = "city" })
@Html.ValidationMessageFor(model => model.City)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Country)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.Country, new { id = "country" })
@Html.ValidationMessageFor(model => model.Country)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
When running my application, it will show watermark effect like below image.
https://i.stack.imgur.com/XcLxZ.png
But when i press create button form validation stop working. when i comment the script to appy watermark it will show my form validation like this
https://i.stack.imgur.com/iEym3.png
But i want validation text in textbox and how can i do this? waiting for the reply :)