我需要将验证摘要包装在div中.当出现错误时,如何设置验证摘要以将其包装为div?
<div class="validation-summary"> <%= Html.ValidationSummary("Login was unsuccessful. Please correct the errors and try again.") %> </div>
解决方法
我不得不在我的另一个项目中扩展验证摘要,以处理一个页面上的多个表单.
虽然这是不同的,你可以创建自己的扩展方法…
namespace System.Web.Mvc { public static class ViewExtensions { public static string MyValidationSummary(this HtmlHelper html,string validationMessage) { if (!html.ViewData.ModelState.IsValid) { return "<div class=\"validation-summary\">" + html.ValidationSummary(validationMessage) + "</div>" } return ""; } } }
然后打电话
<%= Html.MyValidationSummary( "Login was unsuccessful. Please correct the errors and try again.") %>
HTHS,查尔斯
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。