Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Html.ValidationSummary()

I'm having problems the default Html.ValidationSummary() in MVC 3.

As default it adds this code:

<ul>
  <li style="display:none"></li>
</ul>

And that empty <ul> causes space I would like to get rid of.

Is there some way to work around this problem? Make it toggle some div around it or similar?

like image 360
Lasse Edsvik Avatar asked Jun 30 '26 07:06

Lasse Edsvik


2 Answers

how about conditionally showing ValidationSummary

if(!ViewData.ModelState.IsValid)
 {
     @Html.ValidationSummary() 
 }

important if you do this you won't be able to use client-side javascript validation (as the div wont be present)

like image 88
wal Avatar answered Jul 03 '26 20:07

wal


You can create your own validation summary, for example, like here: Custom ValidationSummary template Asp.net MVC 3

like image 34
webdeveloper Avatar answered Jul 03 '26 20:07

webdeveloper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!