Asp.net mvc 4 Kendoui |网格|网格中的服务器端验证
我使用带有ClientTemplate的kendoui网格在网格的每一行上显示文本框。 我需要在网格的每个空文本框上显示验证消息,单击网格外的按钮,该按钮将实际发布数据 看法 我尝试在网格绑定到的模型上设置数据注释,但不幸的是,它不起作用 让我知道是否有人有相同的解决方案。Asp.net mvc 4 Kendoui |网格|网格中的服务器端验证,asp.net-mvc-4,entity-framework-5,kendo-ui-mvc,Asp.net Mvc 4,Entity Framework 5,Kendo Ui Mvc,我使用带有ClientTemplate的kendoui网格在网格的每一行上显示文本框。 我需要在网格的每个空文本框上显示验证消息,单击网格外的按钮,该按钮将实际发布数据 看法 我尝试在网格绑定到的模型上设置数据注释,但不幸的是,它不起作用 让我知道是否有人有相同的解决方案。 <script type="text/javascript"> $(function () { var form = $('#yourFormName'); form.da
<script type="text/javascript">
$(function () {
var form = $('#yourFormName');
form.data('validator').settings.ignore = ''; // default is ":hidden".
});
</script>
$(函数(){
var form=$(“#yourFormName”);
form.data('validator').settings.ignore='';//默认值为:hidden”。
});
//设置DataAnnotation属性
public IList<SelectListItem> SecretQuestion1IdList { get; set; }
[DisplayName("Answer to First Secret Question")]
[Required]
public string SecretQuestionAnswer1 { get; set; }
[DisplayName("Second Secret Question")]
[Required]
public int SecretQuestion2Id { get; set; }
public IList<SelectListItem> SecretQuestion2IdList { get; set; }
[DisplayName("Answer to Second Secret Question")]
[Required]
public string SecretQuestionAnswer2 { get; set; }
[Required]
public int TrustedDomainId { get; set; }
public IList<SelectListItem> TrustedDomain { get; set; }
}
@model ExternalUserManagement.Web.Mvc.Controllers.ViewModels.Register.RegisterPageViewModel
@{
ViewBag.Title = "Register";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="accountDetails" class="centre-container">
@using (Ajax.BeginForm("CreateAccount", "Register",
new AjaxOptions
{
UpdateTargetId = "accountDetails",
OnBegin = "windowHelper.displayWaitingDialog('Saving Registration Details, please wait...')",
OnComplete = "windowHelper.close()"
}))
{
<p class="message information">Register you details, then click submit.</p>
<div class="row">
@Html.LabelFor(m => m.FirstName, new { @class = "label" })
@Html.TextBoxFor(m => m.FirstName, new { @class = "input k-textbox" })
</div>
<div class="row">
@Html.LabelFor(m => m.LastName, new { @class = "label" })
@Html.TextBoxFor(m => m.LastName, new { @class = "input k-textbox" })
</div>
<div class="row">
@Html.LabelFor(m => m.CompanyEmail, new { @class = "label" })
@Html.TextBoxFor(m => m.CompanyEmail, new { @class = "input-left k-textbox" })
@
@(Html.Kendo().DropDownListFor(m => m.TrustedDomainId)
.DataTextField("Text")
.DataValueField("Value")
.BindTo(Model.TrustedDomain)
.OptionLabel(" -- Please Select --")
.HtmlAttributes(new { @class = "input-right" })
)
</div>
<div class="row">
@Html.LabelFor(m => m.BirthDate, new { @class = "label" })
@Html.Kendo().DatePickerFor(m => m.BirthDate).HtmlAttributes(new { @class = "input" })
</div>
<div class="row">
@Html.LabelFor(m => m.SecretQuestion1Id, new { @class = "label" })
@(Html.Kendo().DropDownListFor(m => m.SecretQuestion1Id)
.DataTextField("Text")
.DataValueField("Value")
.BindTo(Model.SecretQuestion1IdList)
.OptionLabel(" -- Please Select --")
.HtmlAttributes(new { @class = "input" })
)
</div>
<div class="row">
@Html.LabelFor(m => m.SecretQuestionAnswer1, new { @class = "label" })
@Html.TextBoxFor(m => m.SecretQuestionAnswer1, new { @class = "input k-textbox" })
</div>
<div class="row">
@Html.LabelFor(m => m.SecretQuestion2Id, new { @class = "label" })
@(Html.Kendo().DropDownListFor(m => m.SecretQuestion2Id)
.DataTextField("Text")
.DataValueField("Value")
.BindTo(Model.SecretQuestion2IdList)
.OptionLabel(" -- Please Select --")
.HtmlAttributes(new { @class = "input" }).AutoBind(true)
)
</div>
<div class="row">
@Html.LabelFor(m => m.SecretQuestionAnswer2, new { @class = "label" })
@Html.TextBoxFor(m => m.SecretQuestionAnswer2, new { @class = "input k-textbox" })
</div>
<div class="captcha row">
@Html.Label("Are you a human?", new { @class = "label" })
<br />
@Html.Raw(Html.GenerateCaptcha("captcha", "clean"))
@Html.ValidationMessage("Invalid Characters")
</div>
<div class="row">
<div class="commands">
<button class="k-button" type="submit" title="Sumbit">
<img src="@Url.Content("~/Content/Images/Icons/disk.png")" alt="" />
Sumbit
</button>
</div>
</div>
}
</div>
public IList SecretQuestion1IdList{get;set;}
[DisplayName(“对第一个秘密问题的回答”)]
[必需]
公共字符串SecretQuestionAnswer1{get;set;}
[显示名称(“第二个秘密问题”)]
[必需]
public int SecretQuestion2Id{get;set;}
公共IList SecretQuestion2IdList{get;set;}
[DisplayName(“对第二个秘密问题的回答”)]
[必需]
公共字符串SecretQuestionAnswer2{get;set;}
[必需]
public int TrustedDomainId{get;set;}
公共IList信任域{get;set;}
}
@模型ExternalUserManagement.Web.Mvc.Controllers.ViewModels.Register.RegisterPageViewModel
@{
ViewBag.Title=“寄存器”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
@使用(Ajax.BeginForm(“CreateAccount”,“Register”,
新选择
{
UpdateTargetId=“accountDetails”,
OnBegin=“windowHelper.displayWaitingDialog('正在保存注册详细信息,请稍候…)”,
OnComplete=“windowHelper.close()”
}))
{
@Html.Raw(Html.GenerateCaptcha(“验证码”、“干净”))
@Html.ValidationMessage(“无效字符”)
萨姆比特
}
@LabelFor(m=>m.FirstName,新的{@class=“label”})
@Html.TextBoxFor(m=>m.FirstName,新的{@class=“input k-textbox”})
@LabelFor(m=>m.LastName,新的{@class=“label”})
@Html.TextBoxFor(m=>m.LastName,新的{@class=“input k-textbox”})
@LabelFor(m=>m.CompanyEmail,新的{@class=“label”})
@Html.TextBoxFor(m=>m.CompanyEmail,新的{@class=“input left k-textbox”})
@
@(Html.Kendo().DropDownListFor(m=>m.TrustedDomainId)
.DataTextField(“文本”)
.DataValueField(“值”)
.BindTo(Model.TrustedDomain)
.OptionLabel(“--请选择--”)
.HtmlAttributes(新的{@class=“input right”})
)
@LabelFor(m=>m.BirthDate,新的{@class=“label”})
@Html.Kendo().DatePickerFor(m=>m.BirthDate).HtmlAttributes(新的{@class=“input”})
@LabelFor(m=>m.SecretQuestion1Id,新的{@class=“label”})
@(Html.Kendo().DropDownListFor(m=>m.SecretQuestion1Id)
.DataTextField(“文本”)
.DataValueField(“值”)
.BindTo(Model.SecretQuestion1IdList)
.OptionLabel(“--请选择--”)
.HtmlAttributes(新的{@class=“input”})
)
@LabelFor(m=>m.SecretQuestionAnswer1,新的{@class=“label”})
@Html.TextBoxFor(m=>m.SecretQuestionAnswer1,新的{@class=“input k-textbox”})
@LabelFor(m=>m.SecretQuestion2Id,新的{@class=“label”})
@(Html.Kendo().DropDownListFor(m=>m.SecretQuestion2Id)
.DataTextField(“文本”)
.DataValueField(“值”)
.BindTo(Model.SecretQuestion2IdList)
.OptionLabel(“--请选择--”)
.HtmlAttributes(新的{@class=“input”}).AutoBind(true)
)
@LabelFor(m=>m.SecretQuestionAnswer2,新的{@class=“label”})
@Html.TextBoxFor(m=>m.SecretQuestionAnswer2,新的{@class=“input k-textbox”})
@Label(“你是人类吗?”,新的{@class=“Label”})
请看下面的图片
链接:
<script type="text/javascript">
$(function () {
var form = $('#yourFormName');
form.data('validator').settings.ignore = ''; // default is ":hidden".
});
</script>
public IList<SelectListItem> SecretQuestion1IdList { get; set; }
[DisplayName("Answer to First Secret Question")]
[Required]
public string SecretQuestionAnswer1 { get; set; }
[DisplayName("Second Secret Question")]
[Required]
public int SecretQuestion2Id { get; set; }
public IList<SelectListItem> SecretQuestion2IdList { get; set; }
[DisplayName("Answer to Second Secret Question")]
[Required]
public string SecretQuestionAnswer2 { get; set; }
[Required]
public int TrustedDomainId { get; set; }
public IList<SelectListItem> TrustedDomain { get; set; }
}
@model ExternalUserManagement.Web.Mvc.Controllers.ViewModels.Register.RegisterPageViewModel
@{
ViewBag.Title = "Register";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="accountDetails" class="centre-container">
@using (Ajax.BeginForm("CreateAccount", "Register",
new AjaxOptions
{
UpdateTargetId = "accountDetails",
OnBegin = "windowHelper.displayWaitingDialog('Saving Registration Details, please wait...')",
OnComplete = "windowHelper.close()"
}))
{
<p class="message information">Register you details, then click submit.</p>
<div class="row">
@Html.LabelFor(m => m.FirstName, new { @class = "label" })
@Html.TextBoxFor(m => m.FirstName, new { @class = "input k-textbox" })
</div>
<div class="row">
@Html.LabelFor(m => m.LastName, new { @class = "label" })
@Html.TextBoxFor(m => m.LastName, new { @class = "input k-textbox" })
</div>
<div class="row">
@Html.LabelFor(m => m.CompanyEmail, new { @class = "label" })
@Html.TextBoxFor(m => m.CompanyEmail, new { @class = "input-left k-textbox" })
@
@(Html.Kendo().DropDownListFor(m => m.TrustedDomainId)
.DataTextField("Text")
.DataValueField("Value")
.BindTo(Model.TrustedDomain)
.OptionLabel(" -- Please Select --")
.HtmlAttributes(new { @class = "input-right" })
)
</div>
<div class="row">
@Html.LabelFor(m => m.BirthDate, new { @class = "label" })
@Html.Kendo().DatePickerFor(m => m.BirthDate).HtmlAttributes(new { @class = "input" })
</div>
<div class="row">
@Html.LabelFor(m => m.SecretQuestion1Id, new { @class = "label" })
@(Html.Kendo().DropDownListFor(m => m.SecretQuestion1Id)
.DataTextField("Text")
.DataValueField("Value")
.BindTo(Model.SecretQuestion1IdList)
.OptionLabel(" -- Please Select --")
.HtmlAttributes(new { @class = "input" })
)
</div>
<div class="row">
@Html.LabelFor(m => m.SecretQuestionAnswer1, new { @class = "label" })
@Html.TextBoxFor(m => m.SecretQuestionAnswer1, new { @class = "input k-textbox" })
</div>
<div class="row">
@Html.LabelFor(m => m.SecretQuestion2Id, new { @class = "label" })
@(Html.Kendo().DropDownListFor(m => m.SecretQuestion2Id)
.DataTextField("Text")
.DataValueField("Value")
.BindTo(Model.SecretQuestion2IdList)
.OptionLabel(" -- Please Select --")
.HtmlAttributes(new { @class = "input" }).AutoBind(true)
)
</div>
<div class="row">
@Html.LabelFor(m => m.SecretQuestionAnswer2, new { @class = "label" })
@Html.TextBoxFor(m => m.SecretQuestionAnswer2, new { @class = "input k-textbox" })
</div>
<div class="captcha row">
@Html.Label("Are you a human?", new { @class = "label" })
<br />
@Html.Raw(Html.GenerateCaptcha("captcha", "clean"))
@Html.ValidationMessage("Invalid Characters")
</div>
<div class="row">
<div class="commands">
<button class="k-button" type="submit" title="Sumbit">
<img src="@Url.Content("~/Content/Images/Icons/disk.png")" alt="" />
Sumbit
</button>
</div>
</div>
}
</div>