我是 mvc3 的新手。我想使用 Jquery Watermark 效果开发表单验证。如果发生任何错误,文本框边框将以红色突出显示,并且仅在文本框中显示错误验证。
我的模型是这样的,
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; }
}
我的查看页面代码是这样的
@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>
}
运行我的应用程序时,它会显示如下图所示的水印效果。
但是当我按下创建按钮表单验证停止工作。当我评论脚本以应用水印时,它将像这样显示我的表单验证
但我想要文本框中的验证文本,我该怎么做?等待回复:)