Apply Twitter Bootstrap Validation Style and Message to ASP.NET MVC validation

前端 未结 12 1723
星月不相逢
星月不相逢 2021-01-30 00:57

How can I integrate ASP.NET MVC unobtrusive validation and Twitter Bootstrap? I want to have all those validation messages and styles appropria

12条回答
  •  無奈伤痛
    2021-01-30 01:41

    This is a neat solution that gives you more control over how the ValidationSummary renders errors to the view. The Unordered List it produced did not look right inside the alert. Therefore, I simply looped through the errors and rendered them how I wanted - using paragraphs in this case. For example:

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

    Which results in a neat Validation Summary Alert:

提交回复
热议问题