It is not possible to execute C # code directly in the client browser because the codes are executed on the server and for the client only pure HTML is returned.
The same concept applies to classic ASP pages, PHP, ASP.Net, etc.
What you can do is through jQuery to call a C # statement on the server, this statement will process and make a return of HTML
Aside from this approach being more performative, you have a gain with security because you imagine writing the direct connection string in the client's browser.
Sample 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 way you can have a north, this code I use in an application with ASP.Net MVC, the page calls the code in postback and returns to the client only what I want (A message, a grid , etc.)
I hope I have helped!