首页 > 解决方案 > 在特定时间提交 Asp.net MVC 后,是否有对 3 个文本框执行操作的功能

问题描述

我将尝试解释这一点,因为它看起来很复杂。我有 3 个文本框输入,我想对第一个输入执行操作,然后在一段时间后自动对第二个输入执行相同的操作,同时在第三个输入上执行操作。

        <form action="@Url.Action("ShowResults")" id="sideForm" method="post" onsubmit="return SidebarValidation()" autocomplete="off">
        <input type="text" class="form-control" id="firstInput" autocomplete="off" name="first" placeholder="Enter Keyword..." value="@Request["first"]"  required><br /><hr />
        <input type="text" class="form-control" id="secondInput" autocomplete="off" name="second" placeholder="Enter Keyword..." value="@Request["second"]" ><br /><hr />
        <input type="text" class="form-control" id="thirdInput" autocomplete="off" name="third" placeholder="Enter Keyword..." value="@Request["third"]" ><br /><hr />
        <div class="col"><button type="submit" id="sdSubmit" name="sideSubmit" class="btn btn-outline-primary" style="font-family: poppins">Custom SEARCH</button></div>
    </form>

这是 view.cshtml,如您所见,我有 3 个输入和提交按钮,当我单击按钮时,我希望在第一个输入上执行操作,5 分钟后执行第二个输入,5 分钟后执行第三个输入,5 分钟后执行再次输入第一个以此类推。

如果有人有线索请帮忙!

标签: c#htmlasp.netasp.net-mvc

解决方案


我希望这将有所帮助。运行这个控制台应用程序,提取你需要的东西。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace FileAdda
{
    public class Example
    {
        static string globalstr = "";
        static List<string> list = new List<string>();
        static void Main(string[] args)
        {
            //assume these as your input values.
            list.Add("Value 1");
            list.Add("Value 2");
            list.Add("Value 3");
            Run();
        }
        public static void Run()
        {
            // You can set it to whatever time you want.
            int seconds = 5 * 1000;
            var timer = new Timer(TimerMethod, null, 0, seconds);
            Console.ReadKey();
        }

        //Put your logic in this method.
        public static void TimerMethod(object o)
        {

            if (string.IsNullOrEmpty(globalstr))
            {
                globalstr = list.FirstOrDefault();
            }
            else
            {
                int lastindex = list.IndexOf(globalstr);
                if (lastindex == (list.Count - 1))
                {
                    globalstr = list[0];
                }
                else
                {
                    globalstr = list[lastindex + 1];
                }
            }
            Console.WriteLine($"The timer callback for {globalstr}");
        }
    }

}

推荐阅读