私はmvc3を初めて使用します。Jquery透かし効果を使用してフォーム検証を開発したいと思います。エラーが発生した場合、テキストボックスの境界線は赤い色で強調表示され、エラー検証はテキストボックスにのみ表示されます。
私のモデルはこんな感じです
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>
}
アプリケーションを実行すると、下の画像のような透かし効果が表示されます。
しかし、作成ボタンを押すと、フォームの検証が機能しなくなります。スクリプトをappy透かしにコメントすると、このようなフォーム検証が表示されます
しかし、テキストボックスに検証テキストが必要ですが、どうすればよいですか?返信を待っています:)