Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Cant put a custom attribute on an html element if a taghelper is on it.

$
0
0

Hello, i want to put a custom attribute on an html element from a string variable like this:

@{
	string foo = "data-foo=hi";<div @foo>Hello</div>
}

This will turn the final html into this:

<div data-foo="hi">Hello</div>

However, if there is a asp.net core taghelper on it (IDE will show the html with purple color) like this:

@{
	string foo = "data-foo=hello";<script asp-append-version="true" @foo></script>
}

Then it doesn't work. The IDE will show the "@foo" with red color. Its supposed to show the "@" with yellow color.
So my solution right now is doing it like this:

@{
	string foo = "hello";<script asp-append-version="true" data-foo="@foo"></script>
}

Now it works.

But i have a situation where i absolutely need to do it where the string foo is "data-foo=hello".

Is there any way i can achieve that?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>