如何从ASP.NET中的C#执行javascript [英] How to execute javascript from c# in asp.net

查看:275
本文介绍了如何从ASP.NET中的C#执行javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在asp.net mvc应用程序上工作,在该应用程序中我必须执行CRON作业才能执行此操作:

I am working on asp.net mvc app in which i have to perform CRON job to execute this:

==>我必须每两分钟执行一次我的应用程序的网页(其中包含ajax请求).就像不时跟踪某人.

==> I have to execute webpage of my application (which contains ajax request) after every two mins. It like tracking someone time to time.

(它基本上是在执行google map api,因此必须强制使用javascript)

(it is basically executing google map api so usage of javascript is compulsory)

我想知道如何执行包含与我们在浏览器上执行的JavaScript相同的网页.我每两分钟调用一次cron作业调用的MVC中的Application_BeginRequest函数.那么如何执行包含javascript的演示页面.

I am wondering how to execute webpage containing javascript same as we execute on browser. I m invoking Application_BeginRequest function in MVC that is called by cron job after every two mins. So how to execute demo page containing javascript.

我已经搜索了很多,但是没有找到任何有用的资源.

I have searched alot but did'nt find any useful resources.

修改: 申请工作:

1- CRON作业每两分钟调用一次Application_Begin函数

1- CRON job calls Application_Begin function after every two mins

2-然后我要调用包含JavaScript和Ajax请求的DemoPage.首先,当请求演示"页面时,对服务器进行ajax调用,返回一些数据 3.然后从ajax成功开始,我使用javascript google map api(使用RouteBox,在路线上定位latlng)执行响应数据以及其他一些数据.

2- Then i want to call DemoPage which contains javascript and ajax request. first when Demo page requested, ajax call made to server which returns some data 3. Then from ajax success, i execute response data with some other data using javascript google map api ( with RouteBox, locating latlng on route ).

3-如果点不在路线中,它将发送警报电子邮件.

3- If point is not in route, it will send alert email.

很难解释我想要什么,但是我想你明白我的意思了吗?

Its little difficult to explain what i want, but i guess you got my point ?

更多详细信息:

当请求页面时,它返回route的json字符串,并且我有latlngs列表,我需要针对该json字符串进行测试,该列表由用javascritp编写的RouteBox类完成.

When page requested, it returns json string of route, and i have list of latlngs which i need to test against that json string which is done by RouteBox class written in javascritp.

推荐答案

您可以从控制器返回脚本:

You can return script from your controller:

public ActionResult SampleAction()
        {
            return JavaScript("alert(Sample!');");
        }

这篇关于如何从ASP.NET中的C#执行javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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