It is not possible to execute C# code directly in the client browser, because the codes are executed on the server and only the pure HTML is returned to the client.
The same concept applies to classic ASP pages, PHP, ASP.Net, etc.
What you can do is by calling jQuery a C# statement on the server, this statement will process and make an HTML return
In addition to this approach being more performative, you have a gain with security, because, imagine writing the connection string directly in the client’s browser.
Example of postback code with jQuery:
$.ajax({
url: "@Url.Action("DeleteMessage", "Home")",
type: "POST",
data: { messageid: GetCurrentMessageID(), mailbox: GetCurrentMailbox() },
dataType: 'json',
cache: false,
success: function (data) {
//Sucesso, faça algo
},
error: function (jqXHR, exception) {
//Erro
}
});
I think that so you can have a north, this code I use in an application with ASP.Net MVC, the page makes the call of the code postback and returns to the client only what I want (A message, a grid, etc.)
I hope I’ve helped!
Direct in browser? Javascript type?
– Jéf Bueno
@jbueno, yes type Javascript
– Daniel
Not at first. I won’t tell you it’s impossible, but it must be a lot of work for little result. Why exactly do you need this? Perhaps, if I explain your problem, we can show you a solution (I’m sure this is not the most viable solution)
– Jéf Bueno
@jbueno, type was just a curiosity type if to some point integrate HTML and C#, as HTML and JS , Ruby and HTML, because check this could help many beginners in Web Programming who already know how to program in this language. Or in the case of an online editor build only a debug to C#
– Daniel
@Daniel the "J" done is to edit the question and specify better what you want
– João Victor Gomes Moreira
@Daniel, I think you’re confusing things a little bit. Ruby runs on the server (in the same way as C#, PHP, Python, among others) and Javascript runs on the client (in the browser). The best is you [Dit] your question and be more specific, give more details about your question. But anyway, I advise you to read about ASP.NET.
– Jéf Bueno
@jbueno, ok, but as I said it is not a doubt but a Curiosity and while the Extensions just showed as an example.
– Daniel
I don’t know if that’s what you want, but you can run C# directly on this page: https://ideone.com/ choose C# from the list below the box where you type the code.
– Math
@Math, yes this way only directly on my site, but this already leaves a branch : - ]
– Daniel
I get it, you wanted to implement your own compiler online, just like https://www.codecademy.com/ has, right?
– Math
You also have https://dotnetfiddle.net/
– Jéf Bueno
@Math, yes that’s right
– Daniel
@jbueno, ok I’ll see
– Daniel