Jesse Hallam
Jesse Hallam

Reputation: 6964

Render custom content on validation error

I wish to bring attention to fields which have not passed model validation. In the case of a textbox, for example, could a red asterisk be printed?

Such as: @Html.EditorFor(m => m.UserName)<span title="The User Name is required.">*</span>

Upvotes: 0

Views: 78

Answers (1)

Jupaol
Jupaol

Reputation: 21365

Have you tried something simple like this:

@Html.ValidationMessageFor(model => model.UserName, "*")

You need the following scripts:

<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.7.2.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

Upvotes: 1

Related Questions