如何在mvc中调用客户端点击html提交按钮

本文关键字:端点 html 提交 按钮 客户端 客户 mvc 调用 | 更新日期: 2023-09-27 17:57:42

朋友们好,
请帮助我,我是MVC Dot-net的新手,我正在尝试在数据库中插入标签值。我有两个标签,第一个是IP地址,第二个是当前运行时间,还有三个提交按钮签入、签出和执行个人任务。页面上的加载签出和个人任务按钮是隐藏的,只显示2个标签和签入按钮
当我点击checkin按钮时,两个标签都是存储在数据库mssql2008中的值。应启用自动签出和个人任务按钮,并禁用签入按钮
当我在点击事件上使用jquery或java脚本执行此任务时,我在控制器上的插入任务不工作,只有jquery工作。

请帮我如何用html提交按钮调用客户端点击事件。。

我的代码是:查看-->

 <button id="btnchkin" value="CheckIn" type="submit" name="action"/>
  <input type="submit"  id="btntask" name="action"  value="PersonalTask" />
   <input type="submit" id="btnchkout" name="action"  value="CheckOut" />

在脚本标记-->上

 $("#btnchkin").click(function () {
    alert("a");
    //  $('#btnchkin').prop('disabled', true);
    $('#btntask').prop('disabled', false);
    $('#btnchkout').prop('disabled', false);
    $('#btnchkin').prop('disabled', true);
    //alert("b");
});

和控制器-->

[HttpPost]
[ActionName("Index")]
public ActionResult Index( string lblIP1)
{
        DateTime datetime = DateTime.Now;
        string date = datetime.ToString();
        date = datetime.Date.ToString();
        lblIP1 = ipp;
        string ip = lblIP1;
        string s = DateTime.Now.ToString("hh:mm:ss tt");
        EmployeeSchedule emp = new EmployeeSchedule();
        emp.IP = ip;
        emp.CurrentDate = Convert.ToDateTime(date);
        emp.CheckInTime = s.ToString();
        BAL_EmployeeSchedule employeeBusinessLayers = new BAL_EmployeeSchedule();
        employeeBusinessLayers.AddEmployee(emp);
        ViewBag.ip = ipp;

    return View();
}

如何在mvc中调用客户端点击html提交按钮

这是您的控制器方法:

public ActionResult Index()
{
    // return view to show three buttons...
    ViewBag.IsCheckedIn = false;
    return View();
}

以下是您的观点:

<script type="text/javascript">
    $(document).ready(function() {
        @if (ViewBag.IsCheckedIn)
        {
            <text>
                $('#btntask').prop('disabled', false);
                $('#btnchkout').prop('disabled', false);
                $('#btnchkin').prop('disabled', true);
            </text>
        }
        else
        {
            <text>
                $('#btntask').prop('disabled', true);
                $('#btnchkout').prop('disabled', true);
                $('#btnchkin').prop('disabled', false);
            </text>
        }
    });
</script>
<button id="btnchkin" value="CheckIn" type="submit" name="action"/>
<input type="submit"  id="btntask" name="action"  value="PersonalTask" />
<input type="submit" id="btnchkout" name="action"  value="CheckOut" />

这是你的后控制器方法:

[HttpPost]
public ActionResult Index()
{
    ViewBag.IsCheckedIn = true;
    return View();
}

如果这是你想要的,请告诉我。