在C#应用程序中执行JavaScript函数 [英] Execute a JavaScript function in a C# application

查看:147
本文介绍了在C#应用程序中执行JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果不使用WebBrowser控件,我怎么能执行一个JavaScript功能,即从任何浏览器的DOM脱钩的依赖,在C#应用程序?我调查的实施验证规则只有一次,对服务器和客户端验证。见<一href=\"http://stackoverflow.com/questions/265343/automatically-duplicating-business-logic-on-web-client\">this如果你喜欢的问题,以供参考。是否有任何JS间pretor库,我可以使用?

Without using a WebBrowser control, how could I execute a JavaScript function, that is decoupled from any browser DOM dependencies, in a C# application? I am investigating implementing validation rules only once, for both server and client validation. See this question for reference if you like. Are there any JS interpretor libraries I could use?

附录:
我的目标是要自动部署和实际验证的过程中调用完全一样的验证逻辑上的客户端和服务器,没有两者之间的通信。因此,理想情况我会code在JavaScript中我验证逻辑,并呈现该页面。或者,我可以code我在C#中的逻辑,使用脚本#将其转换成JavaScript和呈现该页面。

Addendum: My goal here is to automatically deploy and invoke exactly the same validation logic on client and server, without communication between the two during the actual validation. So, ideally I would code my validation logic in JavaScript, and render that to the page. Alternatively, I could code my logic in C#, convert that to JavaScript using Script#, and render that to the page.

我不想单独的验证功能,维持客户端和服务器端的,我不想AJAX调用服务器验证的功能,我不希望只是客户端或服务器只验证不。

I don't want separate validation functions being maintained client and server side, and I don't want AJAX calls to server validation functions, and I don't want client only or server only validation.

推荐答案

这可以帮助的对于C#/ VB.NET / JScript.NET脚本主机它采用内置类框架内的VB,C#或JavaScript执行脚本。

This may help A script host for C#/VB.NET/JScript.NET it uses built in classes within the Framework to execute script in VB, C# or JavaScript.

它使用 codeDomProvider 来执行脚本,还检查出的一个更复杂的例子这文章。

It uses the CodeDomProvider to execute the scripts, also check out this article for a more complex example.

这篇关于在C#应用程序中执行JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆