I have the following view:
@model MyProject.Models.RegisterViewModel
<div class="content">
<div class="wrapper">
<h2>E-Bill Saver Registration</h2>
<hr />
<div class="columns top-gap">
<div class="first cell width-6 dark-blue-headings">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@*@Html.ValidationSummary("", new { @class = "text-danger" })*@
<div class="form-horizontal">
<div class="form-group">
@Html.Label("Account Number", htmlAttributes: new { @class = "control-label col-md-2 bold" })
<br />@Html.ValidationMessageFor(model => model.AccountNo, "", new { @class = "text-danger" })
<div class="col-md-10">
@Html.EditorFor(model => model.AccountNo, new { htmlAttributes = new { @class = "form-control input" } })
</div>
</div>
<div class="form-group">
@Html.Label("MPNumber", htmlAttributes: new { @class = "control-label col-md-2 bold" })
<br />@Html.ValidationMessageFor(model => model.MPNumber, "", new { @class = "text-danger" })
<div class="col-md-10">
@Html.EditorFor(model => model.MPRN, new { htmlAttributes = new { @class = "form-control input" } })
</div>
</div>
<div class="form-group">
@Html.Label("Email Address", htmlAttributes: new { @class = "control-label col-md-2 bold" })
<br />@Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
<div class="col-md-10">
@Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control input" } })
</div>
</div>
<div class="form-group">
@Html.Label("Confirm Email Address", htmlAttributes: new { @class = "control-label col-md-2 bold" })
<br />@Html.ValidationMessageFor(model => model.ConfirmEmail, "", new { @class = "text-danger" })
<div class="col-md-10">
@Html.EditorFor(model => model.ConfirmEmail, new { htmlAttributes = new { @class = "form-control input" } })
</div>
</div>
<div class="form-group">
@Html.Label("Password", htmlAttributes: new { @class = "control-label col-md-2 bold" })
<br />@Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
<div class="col-md-10">
@Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control input" } })
</div>
</div>
<div class="form-group">
@Html.Label("Confirm Password", htmlAttributes: new { @class = "control-label col-md-2 bold" })
<br />@Html.ValidationMessageFor(model => model.ConfirmPassword, "", new { @class = "text-danger" })
<div class="col-md-10">
@Html.EditorFor(model => model.ConfirmPassword, new { htmlAttributes = new { @class = "form-control input" } })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Register" class="opc_button" />
</div>
</div>
</div>
}
</div>
</div>
</div>
If there are validation errors on any of the fields then the error message is displayed below the label as expected and wanted. On my controller however I have some custom logic errors and I am adding them to the modelstate as follows:
else
{
//This email address is already assigned to a user
ModelState.AddModelError("Email Address : ", "Error! You must enter an email address that is unique to your account.");
return View(model);
}
If I uncomment the validationsummary on my page then it will display the custom server side error but it will also display the single validation errors which I want underneath the labels. Is there any way that I can set the validation summary to ignore the values that are being listed individually and only return server side validation errors?