Show ValidationSummary MVC3 as “alert-error” Bootstrap

后端 未结 16 1315
情书的邮戳
情书的邮戳 2021-01-30 00:51

I want to show a ValidationSummary mcv3 with \"alert-error\" Bootstrap styling.

I\'m using a Razor view, and I show model errors with this code:

 @Html.V         


        
16条回答
  •  抹茶落季
    2021-01-30 01:43

    I did not like how the ValidationSummary rendered using a bullet list (unordered list). It had a lot of unnecessary space below the error list.

    A solution to that issue - is simply to loop through the errors and render the errors how you want. I used paragraphs. For example:

    @if (ViewData.ModelState.Any(x => x.Value.Errors.Any()))
    {
        
    }
    

    The result, in my case, looks something like this:

提交回复
热议问题