jazb
jazb

Reputation: 5791

Can a ViewComponent have it's own seperate js file?

In the same way a normal cshtml file can have a js file section, doe same apply for a ViewComponent? If so are there any gotchas?

Upvotes: 0

Views: 727

Answers (1)

Adam Barnes
Adam Barnes

Reputation: 3203

ViewComponents have their own cshtml files, which render out to plain HTML, so you can just include the javascript as you would in HTML, within the cshtml file:

<script type="text/javascript">
    console.log('rendered viewcomponent');
</script>

Upvotes: 1

Related Questions