Помощник по тегам стиля класса ve [дубликат]C#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Помощник по тегам стиля класса ve [дубликат]

Сообщение Anonymous »

В Smartstore есть следующий тег-помощник. не может использоваться более одного раза в одном и том же div. какие изменения следует внести? помощник тега: AttributesTagHelper
здесь я хочу использовать два или более атрибута класса и стиля атрибута в div.

Код: Выделить всё

using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace Smartstore.Web.TagHelpers.Shared
{
[HtmlTargetElement("*", Attributes = AttributesName)]
[HtmlTargetElement("*", Attributes = ConditionalAttributePrefix + "*")]
public class AttributesTagHelper : TagHelper
{
const string AttributesName = "attrs";
const string ConditionalAttributePrefix = "attr-";

private IDictionary _conditionalAttributes;

/// 
/// We set the order to -1100 to run this TagHelper before .
/// We had to do this because of the QtyInput EditorTemplate which is rendered multiple times on the cart page and needs a unique id and name
/// which will be passed to the EditorTemplate by htmlAttributes dictionary and will be passed to the AttributesTagHelper.
///  does not override the id and name attributes if they are already set.
/// 
public override int Order => -1100;

/// 
/// An  instance whose content should be merged with local attributes.
/// 
[HtmlAttributeName(AttributesName)]
public AttributeDictionary Attributes { get; set; }

/// 
/// Conditional attribute. Output will be suppressed if condition (first value tuple item) evaluates to false.
/// NOTE: the value of conditional class attribute (sm-class) will be appended to existing class attribute.
/// 
[HtmlAttributeName("sm-all-conditional-attrs", DictionaryAttributePrefix = ConditionalAttributePrefix)]
public IDictionary ConditionalAttributes
{
get
{
return _conditionalAttributes ??= new Dictionary(StringComparer.OrdinalIgnoreCase);
}
set
{
_conditionalAttributes = value;
}
}

public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (Attributes != null)
{
foreach (var attr in Attributes)
{
if (attr.Key == "class")
{
output.AppendCssClass(attr.Value);
}
else
{
output.MergeAttribute(attr.Key, attr.Value, attr.Key == "value");
}
}
}

if (_conditionalAttributes != null && _conditionalAttributes.Count > 0)
{
foreach (var kvp in _conditionalAttributes)
{
if (kvp.Value.Condition)
{
if (kvp.Key == "class")
{
output.AppendCssClass(kvp.Value.Value);
}
else
{
output.MergeAttribute(kvp.Key, kvp.Value.Value, kvp.Key == "value");
}
}
}
}
}
}
}
Я пробовал, но результатов не добился. «Похоже, что ваше сообщение состоит в основном из кода; пожалуйста, добавьте больше деталей». эта ошибка, но сколько подробностей я могу дать, вот в чем дело.
Может ли HTML-элемент иметь один и тот же атрибут дважды? (3 ответа) Это не имеет никакого отношения к данной теме.

Подробнее здесь: https://stackoverflow.com/questions/790 ... tag-helper
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Помощник по тегам стиля класса ve [дубликат]
    Anonymous » » в форуме C#
    0 Ответы
    7 Просмотры
    Последнее сообщение Anonymous
  • Пользовательский помощник тегов Razor не применяется ко всем тегам и не устанавливает значение атрибута
    Anonymous » » в форуме C#
    0 Ответы
    14 Просмотры
    Последнее сообщение Anonymous
  • Пользовательский помощник тегов Razor не применяется ко всем тегам и не устанавливает значение атрибута
    Anonymous » » в форуме C#
    0 Ответы
    7 Просмотры
    Последнее сообщение Anonymous
  • Как показать похожие публикации по тегам
    Anonymous » » в форуме Php
    0 Ответы
    8 Просмотры
    Последнее сообщение Anonymous
  • Подсказка jQuery: прикрепление только к тегам привязки к кому-либо
    Anonymous » » в форуме Jquery
    0 Ответы
    17 Просмотры
    Последнее сообщение Anonymous

Вернуться в «C#»