It is easy to display input errors using a field's validation message in a view. Simply call ModelState.AddModelError()
passing in the property ID and error message, then return the View(). It is a great way to tell the user about an issue with their input while keeping them on the same page.
From the controller's Edit() function:
if (NicknameAlreadyExists(SomeNickname)) {
ModelState.AddModelError("Nickname", "Nickname already in use.");
return View();
}
In the view:
@Html.LabelFor(model => model.Nickname, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Nickname, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Nickname, "", new { @class = "text-danger" })