我正在使用 DataAnnotation 进行验证,我想在弹出窗口(对话框/警报)中显示错误消息(数据注释),而不是在视图中显示它......我已经使用这个链接实现了代码......
项目模板是移动的让我知道我是否遗漏了什么?? http://forums.asp.net/t/1738076.aspx/1
Javascript:-
$('#Test').bind('invalid-form.validate', function (form, validator) {
alert('InsideTest');
var $list = $('#errorlist ul:first')
if ($list.length && validator.errorList.length) {
$list.empty();
$.each(validator.errorList, function () {
$("<li />").html(this.message).appendTo(list);
});
$list.dialog({
title: 'Please correct following errors:',
});
}
});
Forgot to add html...
关于.cshtml:-
@model WRDSMobile.Models.Test
<div id="errorlist" style="display:none"><ul></ul></div>
@using (Html.BeginForm(null, null, FormMethod.Post, new { name = "Test", id = "Test" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Test</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Age)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Age)
@Html.ValidationMessageFor(model => model.Age)
</div>
<input type="submit" value="Create" />
</fieldset>
}