htmlrazorbootstrap-4asp.net-core-mvcbootstrap-select

asp-append-version affecting html elements inside _Layout.cshtml


I'm trying to add a language selector with flag in .net core mvc application. The picker selector is working fine but asp version is appended to the options of the dropdown.

<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

If I move the picker in any other file apart from _Layout.cshtml it works fine as expected. Any idea how can I solve this issue?


Solution

  • We can use @Html.Raw to prevent the Razor engine from rendering these contents. So as to meet our needs.

    Using below code

        <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>
    

    Test Result

    enter image description here