如何在C#MVC上制作计时器 [英] How to make a timer on C# MVC

查看:175
本文介绍了如何在C#MVC上制作计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用C#MVC为网站制作计时器功能。使用jquery或ajax启动计时器,并在控制器上计算倒计时值。



请帮帮我

谢谢



我尝试了什么:



我没有得到,首先我设计的设计。现在我正在寻找编码部分。

I want to make a timer function for website using C# MVC. The timer is started using jquery or ajax and the countdown value is calculated on the controller.

Please help me
Thanks

What I have tried:

I didn't get, firstly i designed design. now i looking for coding part.

推荐答案

如果你正在寻找在jquery中实现一个计时器,那么你可能需要使用setTimeout函数。



jQuery setTimeout()函数示例 - SitePoint [ ^ ]



至于获取值,你没有发布任何控制器或查看代码,所以可能没有多大帮助,但假设你知道如何从控制器获取值到你的视图,如果您在视图中使用强类型模型,您只需向模型中添加一个名为 public int Timer {get; set;} 的属性,然后在您的视图中,您只需起诉延迟参数中模型的 Timer 值。



如果你没有使用强类型模型然后你c将计时器值添加到ViewBag键或类似的东西,以将其从控制器添加到模型中。
If you are looking at implementing a timer in jquery then you'll probably need to use the setTimeout function.

jQuery setTimeout() Function Examples — SitePoint[^]

As far as getting the value, you didn't post any controller or view code so probably can't be of much help but assuming you know how to get values from your controller to your view, if you are using a strongly typed model in your view you could just add a property to your model called public int Timer {get;set;} then in your view you would just sue the Timer value from your model in the delay parameter.

If you aren't using a strongly typed model then you can add the timer value to a ViewBag key or something like that to get it from your controller to your model.


这篇关于如何在C#MVC上制作计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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