Reputation: 7702
I have an MVC 4 app and am using HTML.BeginForm to create a form on a View. I have several field sets where I have positioned them on an absolute basis. For example, here is my BeginForm and one of my fieldsets:
<div style="width:1100px; height:490px;">
@using (Html.BeginForm("Create", "BicycleSellerListing", FormMethod.Post, new { enctype = "multipart/form-data" })) {
@Html.ValidationSummary(true)
<fieldset style="position:absolute; top:180px; left:150px; width:550px">
<legend>Bicycle Information</legend>
...
...
The problem is that if there are errors in the ModelState when a submit is done, the errors generated are covered by some of the fields in the fieldsets. Is there a way I can indicate where I want model state errors to display?
Upvotes: 0
Views: 425
Reputation: 11203
There are couple ways to display errors. @Html.ValidationSummary()
will display all of the errors in one place. So depending where you put @Html.ValidationSummary(true)
- that's where errors will be displayed. For example, you can put it after the form, not in the beginning like you have it.
Another way is to use @Html.ValidationMessageFor(...)
helper. It takes your mode's property name so the error will only be displayed for that property. Again, you can put it anywhere you want. Usually people put it next to the input so that error message is displayed next to the input as well.
Upvotes: 1