C#Razor-如何从字符串中删除双引号

问题描述 投票:0回答:1

这是我在浏览器中需要的确切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. 我使用单引号'value'作为值,但我应该使用双“ value”为了匹配示例输出。
c# razor stringbuilder razor-pages
1个回答
0
投票

让它开始工作..

我刚改变

@sb.ToString()

@(new HtmlString(sb.ToString()))
© www.soinside.com 2019 - 2024. All rights reserved.