I have a form in which I want to disable the required validation on one of the @Html.TextBox elements. The front end is as follows:
@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>
}
And the code for the model is as follows:
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; }
}
I'm guessing that the @Html.TextBox has a default validation even though I don't specify it. Is there someway to remove it?, I tried removing the html tags data-val-required and data-val, but still no results.
Thanks