asp-append-version 影响 _Layout.cshtml 内的 html 元素

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

我正在尝试在 .net core mvc 应用程序中添加带有标志的语言选择器。选择器选择器工作正常,但 asp 版本附加到下拉列表的选项中。

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - WebApplication2</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.2/css/bootstrap-select.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/0.8.2/css/flag-icon.min.css">
    <link rel="stylesheet" href="./css/site.css">
    <link rel="stylesheet" href="./WebApplication2.styles.css"  />
</head>
<body>
    <div class="container">
        <main role="main" class="pb-3">
            @RenderBody()
        </main>
        <select class="selectpicker" data-width="fit">
            <option data-content="<span class='flag-icon flag-icon-cz'></span>"></option>
            <option data-content="<span class='flag-icon flag-icon-de'></span>"></option>
            <option data-content="<span class='flag-icon flag-icon-gb'></span>"></option>
        </select>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.6.2/js/bootstrap-select.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script src="./js/site.js"></script>
    <script type='text/javascript'>
        $(function () {
            $('.selectpicker').selectpicker();
        });
    </script>
    @await RenderSectionAsync("Scripts", required: false)
</body>

language picker with appended asp version in options

如果我将选择器移动到除

_Layout.cshtml
之外的任何其他文件中,它会按预期正常工作。知道如何解决这个问题吗?

html razor bootstrap-4 asp.net-core-mvc bootstrap-select
1个回答
0
投票

我们可以使用

@Html.Raw
来阻止
Razor engine
渲染这些内容。从而满足我们的需求。

使用以下代码

    <select class="selectpicker" data-width="fit">
        <option data-content="@Html.Raw("<span class='flag-icon flag-icon-cz'></span>")"></option>
        <option data-content="@Html.Raw("<span class='flag-icon flag-icon-de'></span>")"></option>
        <option data-content="@Html.Raw("<span class='flag-icon flag-icon-gb'></span>")"></option>
    </select>

测试结果

© www.soinside.com 2019 - 2024. All rights reserved.