Amila Dulanjana Amila Dulanjana - 3 months ago 15
C# Question

@apply in polymer is not working in asp.net

I am new to Polymer and ASP.NET. I am trying to develop a ASP.NET project using Polymer. But when I use

@apply()
in Polymer to customize style it give a error like this :


The name 'apply' does not exist in the current context


This is my code

<dom-module id="simple-todo">
<template>
<style is="custom-style">
.flex {
@apply(--layout-horizontal);
}
</style>
<div class="container flex">
<div>one</div>
<div>two</div>
<div>three</div>
</div>
</template>
</dom-module>


Thanx in advance !

Answer

@ has a special meaning in a razor file. This means it is the start of some server code(C#). So razor engine things that apply is a C# method! @ will also do Html encode on the result of the expression following.

You can use Html.Raw() method to handle this case. Raw method will not encode the result

<dom-module id="simple-todo">
    <template>
        <style is="custom-style">
  .flex {    
            @Html.Raw("@apply(--layout-horizontal);")
        }
        </style>
        <div class="container flex">
            <div>one</div>
            <div>two</div>
            <div>three</div>
        </div>
    </template>
</dom-module>