我有一个表单,我想在其中禁用 @Html.TextBox 元素之一所需的验证。前端如下:
@model Models.NewUser
@using (Html.BeginForm("Register", "Account"))
{
<div class="field">
<span class="textOverField absolute em1-2" style="top:6px;left:4px;">Key</span>
@Html.TextBox("SchoolGroupKey", "", new { @class = "textField" })
</div>
<div class="field">
<span class="textOverField absolute em1-2" style="top:6px;left:4px;">Name</span>
@Html.TextBox("Names", "", new { @class = "textField" }) <div class="absolute validationMessage">@Html.ValidationMessageFor(u => u.Names)</div>
</div>
<div class="field">
<span class="textOverField absolute em1-2" style="top:6px;left:4px;">Last Name</span>
@Html.TextBox("LastNames", "", new { @class = "textField" }) <div class="absolute validationMessage">@Html.ValidationMessageFor(u => u.LastNames)</div>
</div>
<div class="em0-9" style="margin-bottom:20px;">
<input class="submitButton cursorHand" style="margin-top:10px;" type="submit" value="Registrarme" />
</div>
}
该模型的代码如下:
public class NewUser
{
[Required(ErrorMessage = "Name required")]
public string Names { get; set; }
[Required(ErrorMessage = "Last name required")]
public string LastNames { get; set; }
public System.Guid SchoolGroupKey { get; set; }
}
我猜 @Html.TextBox 有一个默认验证,即使我没有指定它。有没有办法删除它?,我尝试删除 html 标签 data-val-required 和 data-val,但仍然没有结果。
谢谢