Browse Source

Update AbpTagHelperAttributeListExtensions.cs

resolves https://github.com/abpframework/abp/issues/1421
pull/1428/head
Yunus Emre Kalkan 7 years ago
parent
commit
f3bdcefcfc
  1. 17
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/Microsoft/AspNetCore/Razor/TagHelpers/AbpTagHelperAttributeListExtensions.cs

17
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/Microsoft/AspNetCore/Razor/TagHelpers/AbpTagHelperAttributeListExtensions.cs

@ -1,4 +1,6 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.AspNetCore.Razor.TagHelpers;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers
@ -19,8 +21,11 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHel
} }
else else
{ {
//TODO: Check if it's already added before! var existingClasses = classAttribute.Value.ToString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
attributes.SetAttribute("class", classAttribute.Value + " " + className); if (!existingClasses.Contains(className))
{
attributes.SetAttribute("class", classAttribute.Value + " " + className);
}
} }
} }
@ -37,8 +42,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHel
return; return;
} }
//Can be optimized? var existingClassList = classAttribute.Value.ToString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
attributes.SetAttribute("class", classAttribute.Value.ToString().Split(' ').RemoveAll(c => c == className).JoinAsString(" ")); var modifiedClassList = existingClassList.RemoveAll(c => c == className);
attributes.SetAttribute("class", modifiedClassList.JoinAsString(" "));
} }
public static void AddIfNotContains(this TagHelperAttributeList attributes, string name, object value) public static void AddIfNotContains(this TagHelperAttributeList attributes, string name, object value)

Loading…
Cancel
Save