我需要将验证摘要包装在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,查尔斯