Displaying HTML with values from variables in the dotnet kernel

Displaying HTML with values from variables in the dotnet kernel

How to display HTML with values from variables in the dotnet kernel in .NET Interactive Notebooks.

There are a few ways to get your interactive notebooks to write HTML to the client.

  1. Using the #!html and #!js magic commands.
  2. Using the PocketView API.
  3. Using the HtmlContentBuilder class.

Here are a few examples of how to display HTML with values from variables in the dotnet kernel.

1) Using the HTML and JS kernels

In this first example we must create the variable and assign it a value in a C## notebook cell.

Then using a multi-language single notebook cell, we can write our HTML and JavaScript to retrieve the variable and then replace the innerHTML of the div tag.

2) Using the PocketView API

This second example, although simple, is using the PocketView API returning an IHtmlContent.

As we can see, it can get complicated writing code using the PocketView API if you are not familiar with it.

Here is another example using the PocketView API with an a tag.

For more information on how to use the PocketView API, please refer to the PocketView API documentaion on the dotnet interactive GitHub repository.

3) Using the HtmlContentBuilder class

The third way makes use of the HtmlContentBuilder class. The functionality closely resembles using a StringBuilder.

Notice that you have to import the `Microsoft.AspNetCore.Html_` namespace._

Conclusion

Using the #!html and #!js magic commands, the PocketView API, and the HtmlContentBuilder class you have plenty of options for crafting and rendering HTML in all your .NET interactive notebooks.

What if there was another, more familiar way to mix HTML and C## code?

Check out my next post for how to achieve the same result using Razor markup.

dotnet html

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Know Everything About HTML With HTML Experts

HTML Assignment Help Australia @30% OFF from Sample Assignment, with Our Best HTML assignment help experts. Get HTML homework help online at affordable price. 100% Plag free assignment solution.

HTML Tutorial For Beginners

In this article, we’ll tutorial the best ways for learning HTML to assist you on your programming journey.

Commonly Used HTML Tags with Examples

HTML tags are keywords used in HTML to display web-pages with certain properties. They are further used for defining HTML elements. An HTML element consists of a starting tag.

HTML Basics to Learn HTML for Web Development

HTML is the mark-up language most websites are written in. In this article, we will delve into the most basics of HTML like tags and elements that are of utmost importance while writing any code in HTML. These tags help in the structuring and display of content on the web pages.

Types, Effects and Attributes

Learn about HTML Button & various effects on these buttons like ripple, fade-in & pressed. Learn types of HTML buttons - shaded button, animated button etc.