我有一个这样的模型:
public class SignUpModel
{
[Required, DisplayName(@"Particulars/Salutation")]
public short Salutation { get; set; }
public IEnumerable<SalutationOption> SalutationOptions { get; set; }
[Required, DisplayName("Particulars/FirstName")]
public string FirstName { get; set; }
[Required, Display(Name = "Particulars/LastName")]
public string LastName { get; set; }
[Required, DataType(DataType.EmailAddress), Display(Name = "Particulars/Email")]
public string Email { get; set; }
[Required, DataType(DataType.EmailAddress), Compare("Email"), Display(Name = "Particulars/EmailConfirmation")]
public string EmailConfirmation { get; set; }
}
现在,在我看来,我想使用@Html.ValidationMessageFor
发布验证错误(也是客户端)。
<div class="section-field">
<div class="form-group">
@Html.LabelFor(model => model.Email, new { @class = "control-label required" })
@Html.EditorFor(model => model.Email, new { htmlAttributes = new { autocomplete = "off" } })
@Html.ValidationMessageFor(x=>x.Email);
</div>
</div>
<div class="section-field">
<div class="form-group">
@Html.LabelFor(model => model.EmailConfirmation, new { @class = "control-label required" })
@Html.EditorFor(model => model.EmailConfirmation, new { htmlAttributes = new { autocomplete = "off" } })
@Html.ValidationMessageFor(x=>x.EmailConfirmation);
</div>
</div>
但是在Html.ValidationMessageFor
中,我只想显示“无效的电子邮件地址”或“两个电子邮件必须匹配”之类的内容。
我不想显示这样的信息,即所有字段都是必填字段,因为它们都是必填字段,并且它们都用红色边框显示。
有可能吗?尝试实现自定义的HtmlHelper,但这不会过滤客户端任何内容。
答案 0 :(得分:0)
所以我现在简单地使用CSS修复它。
我将类var array = [String]()
func create() {
var arrayCount = array.count // will be 0
var nameForUI = "view/(arrayCount)" // will be view0
let nameForUI: UIVIew = {
let view = UIVIew()
return view
}()
array.append(nameForUI)
view.addSubview(nameForUI)
//
}
添加到无效的required-validation
验证中:
Required
并添加到我的<p class="validation-error required-validation">The field 'FirstName' is required</p>
custom.css
欢迎提供有关如何使用ASP处理此问题的其他想法:)