【问题标题】:C# Razor - How do you remove double quotes from stringC# Razor - 如何从字符串中删除双引号
【发布时间】:2020-07-10 07:19:17
【问题描述】:

这是我想要在浏览器中准确输出的 html:

<button class="snipcart-add-item"
        data-item-id="starry-night"
        data-item-price="8.00"
        data-item-url="menu/rice-meals/"
        data-item-description="Best Rice in town"
        data-item-image="/media/v01dq2ye/rice-small.jpg"
        data-item-name="Jollof Rice"

        data-item-custom1-name="Stew"
        data-item-custom1-options="Aye-Mase|Red"

        data-item-custom2-name="Side"
        data-item-custom2-options="Beans|Plantain|Plantain & Beans[+0.50]"

        data-item-custom3-name="Meat"
        data-item-custom3-options="Fuku|Beef|Cow foot[+1.00]"

        data-item-custom4-name="rice"
        data-item-custom4-options="White|Jollof Rice| Fried Rice[+1.00]">

    Add to cart
</button>

这是我的剃须刀:

    <button class="snipcart-add-item"
        data-item-id="@product.ProductId"
        data-item-price="@product.Price"
        data-item-url="@product.ProductUrl"
        data-item-description="Need to put a description here"
        data-item-image="@product.ProductImageUrl"
        data-item-name="@product.ProductName"

        @{
            var sb = new StringBuilder();
            int currentCount = 1;
        }

        @foreach (var option in product.ProductOptions)
        {
            sb.Append(string.Format("data-item-custom{0}-name='{1}'", currentCount,option.OptionName));

            sb.Append(string.Format("data-item-custom{0}-options='{1}'", currentCount, option.OptionsAsSnipCartString));

            currentCount++;
        }

        @sb.ToString()
        >

    Add to cart
</button>

这是我得到的输出,几乎它不太正确,我有一个额外的引号。

data-item-custom1-name="'Stew'
data-item-custom1-options='Aya-Mase|Red-Stew'
data-item-custom2-name='Rice'
data-item-custom2-options='Jollof-Rice|White-Rice|Fried-Rice'
data-item-custom3-name='Side'
data-item-custom3-options='Plaintain|Beans|Plaintain-And-Beans[+0.50]'
data-item-custom4-name='Meat'data-item-custom4-options='Beef|Shaki|Fuku|Abodi'">

    Add to cart
</button>

谁能帮帮我?

  1. 我在“整个事物”周围有“”,我需要从输出中删除它。
  2. 我使用单引号“值”作为值,但我应该使用双“值” 匹配示例输出。

【问题讨论】:

  • 如果你只使用"data-item-custom{0}-name={1}"怎么样
  • @Sajid 你是什么意思?
  • 如果我理解正确的问题,我的意思是 sb.Append(string.Format("data-item-custom{0}-name={1}", currentCount,option.OptionName)); 没有单引号

标签: c# razor stringbuilder razor-pages


【解决方案1】:

让它工作..

我只是变了

@sb.ToString()

到

@(new HtmlString(sb.ToString()))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2013-10-09
    • 2012-09-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多