Changing text if a form has an error

I currently have a summary message at the top of my form, inviting my user to login. If the form does not validate on submit, I wish for this to then be replaced with the relevant error.

The only way I can think of is by hiding the initial text (perhaps in a @Html.Label) and then showing a @Html.ValidationSummary. However, I feel there is most likely a far more efficient way of doing this.

Can anybody help?


I would have an @Html.Label helper, and use the ViewBag object to pass data to it. That way in your controller when you test for ModelState.IsValid, if that is false you can set the ViewBag property so that it passes to the label helper.

Make sense? That's how I'd do it.

Need Your Help

Melt and dcast based on the name of the original data frame column

r reshape

I'm having a hard time reshaping a dataframe for use with error bar plots, combining all the columns with centeral-tendency data and, separately, all the columns with error data.