I don't know if this is already possible or not, but could Blazor be used just for getting C# working as client-side code in place of JavaScript, while keeping the regular html / css rendering?
If I could preempt one comment: No, I'm not trying to replace every day little client-side javascript, but for more significant use cases.
Here's one example: See this blazedown experiment. Like him, I happen to be using MarkDig on the backend to render markdown, while for the ongoing preview while client types, I make calls to the backend every half second etc to render an html preview panel of the document (yes, I could use, as I did originally, one of the javascript based MD renderers, but without going into details, this way gives me consistent and better results to what I'm doing on the backend for rendering). It would be terrific if MarkDig could be compiled and used client-side with Blazor, using whatever it does to get .NET working with webassembly on the client, without replacing the UI. So I'm envisioning a way to probably use javascript to call functions in the webassembly / blazor .NET code. Or is that just not possible?
Thanks y'all
could Blazor be used just for getting C# working as client-side code in place of JavaScript, while keeping the regular html / css rendering?
Yes, that's exactly what Blazor enables.
See this blazedown experiment. Like him, I happen to be using MarkDig on the backend to render markdown
Actually, I don't think that's what BlazeDown does. BlazeDown doesn't make server requests to do the markdown to HTML conversion. Instead, BlazeDown uses MarkDig to render the markdown into HTML directly in the browser. This is possible because Blazor supports .NET Standad libraries.
It would be terrific if MarkDig could be compiled and used client-side with Blazor, using whatever it does to get .NET working with webassembly on the client, without replacing the UI
Yup, that's basically what BlazeDown demonstrates. There are some rough edges. For example we don't have support yet for rendering raw HTML from a Blazor component yet (#167), so BlazeDown had to do some hacks. Also, Blazor is really intended to be used for your entire app, not individual widgets. But otherwise Blazor matches up pretty well to what you are asking for.
See https://blazor.net to learn more.
Thanks for the response! I'm very encouraged to hear this. My impression thus far was that Blazor replaces the entire UI using Razor code somehow compiled to display as html, which to be clear is awesome... but it wasn't so clear you could use this just to get the C# "scripting" part (better yet: real object oriented C# "coding" with full .NET libraries!) but while using just plain html/css otherwise. The homepage states: "Build a Web UI with C#" - and most articles thus far focused on razor (even the one I referenced, the part about it being hackish to display html, I probably misunderstood that as referring to all html displaying, I guess now he might have just meant for the final markdig-to-html injection part). Anyways, looks like I just need to go try one of these demos myself to clear up misconceptions I had.
One clarification, I worded this poorly, but when I said: "Like him, I happen to be using MarkDig on the backend to render markdown", what I meant to say was just that I am also using Markdig for this conversion, mine though being on the backend, the whole point being I would love it to be client side.
My impression thus far was that Blazor replaces the entire UI using Razor code somehow compiled to display as html, which to be clear is awesome... but it wasn't so clear you could use this just to get the C# "scripting" part (better yet: real object oriented C# "coding" with full .NET libraries!) but while using just plain html/css otherwise
Hmm . . . maybe I'm misunderstanding the distinction your making. In Blazor you do use Razor files (.cshtml) to define what HTML you want rendered. The Razor files get compiled into Blazor component classes that capture the HTML to render and Blazor handles updating the DOM accordingly. So you can't just type some C# into an HTML file and have that somehow get interpreted in the browser - the process is more like how systems like React work. Does that make sense?
So you can't just type some C# into an HTML file and have that somehow get interpreted in the browser
Ah, ok, so it sounds like the answer to my question is _no_.
I wonder why not though. It would be cool to have netstandard assemblies compiled to a webassembly format (perhaps doing some of the same things Blazor does) that could be called let's say from a javascript function, so then the javascript function is just used to make the initial call into the webassembly code (originally C#). It seems like Blazor does even more than this by providing a whole (awesome) UI razor framework, so I assumed / hoped a more minimal use case could be done. To run C# code compiled to webassembly as a javascript replacement (in certain use cases, to be clear).
The code example I gave above would be perfect for this: I already have a working UI, with a javascript based MarkDown editor, but am using my own preview rendering for the right hand side, which taps the backend with ajax calls in the background to get the final html rendering from the server (to be clear: we do quite a few extra custom things on top of just rendering the MarkDown, so there is a LOT of C# code that goes into getting a final html rendering, which is why we are going to the trouble of contacting the server incessantly to get previews). But if it were possible to take this large amount of C# code, part of which depends on MarkDig, it could be client side then and render a whole lot more often and quicker.
Blazor sits on top of mono/wasm which provides the .net runtime in the browser. You don鈥檛 have to use Blazor to get c# in the browser, but it might take a lot of work to do it all yourself. Give it a try
Sent with GitHawk
Looks like I needed to read this page: Blazor, Razor, WebAssembly, and Mono: How the pieces fit together