如何调用HTML客户端点击MVC中提交按钮 [英] How to call client side click on html submit button in mvc

查看:150
本文介绍了如何调用HTML客户端点击MVC中提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好朋友,结果
 请帮助我,我在MVC点网新,我试图在数据库中插入标签值我有两个标签首先为IP地址,第二次对当前运行时间和签,签和去为个人任务三提交按钮。
 在页面加载结帐和个人任务按钮被隐藏,只显示2标签和按钮来检查。结果
 当我点击按钮签标签都存储看重数据库SQL2008毫秒。并自动结帐和个人任务按钮应启用并为您在按钮应禁用。结果
           当我在做的控制器使用jQuery或Java脚本此任务单击事件,然后我插入任务不工作只是jQuery的工作。

请帮我,我怎么可以在调用客户端的点击事件与HTML提交按钮。

我的code是:
  查看 - >

 <按钮ID =btnchkinVALUE =检入类型=提交名称=行动/>
  <输入类型=提交ID =btntaskNAME =行动值=PersonalTask​​/>
   <输入类型=提交ID =btnchkoutNAME =行动值=结帐/>

在script标签 - >

  $(#btnchkin)。点击(函数(){    警报(一);
    // $('#btnchkin')丙(禁用,真正的)。
    $('#btntask')丙(禁用,假);
    $('#btnchkout')丙(禁用,假);
    $('#btnchkin')丙(禁用,真正的);    //警报(B);
});

和控制器 - >

  [HttpPost]
[ActionName(指数)]
公众的ActionResult指数(字符串lblIP1)
{        日期时间日期时间= DateTime.Now;
        字符串日期=则DateTime.ToString();
        日期= datetime.Date.ToString();
        lblIP1 = IPP;
        串IP = lblIP1;        字符串s = DateTime.Now.ToString(HH:MM:SS TT);        EmployeeSchedule EMP =新EmployeeSchedule();
        emp.IP = IP;
        emp.CurrentDate = Convert.ToDateTime(日期);
        emp.CheckInTime = s.ToString();        BAL_EmployeeSchedule employeeBusinessLayers =新BAL_EmployeeSchedule();
        employeeBusinessLayers.AddEmployee(EMP);        ViewBag.ip = IPP;
    返回查看();
}


解决方案

下面是你的控制器的方法:

 公众的ActionResult指数()
{
    //返回视图显示三个按钮...
    ViewBag.IsCheckedIn = FALSE;
    返回查看();
}

下面是您的视图:

 <脚本类型=文/ JavaScript的>
    $(文件)。就绪(函数(){
        @if(ViewBag.IsCheckedIn)
        {
            <文字和GT;
                $('#btntask')丙(禁用,假);
                $('#btnchkout')丙(禁用,假);
                $('#btnchkin')丙(禁用,真正的);
            < /文字和GT;
        }
        其他
        {
            <文字和GT;
                $('#btntask')丙(禁用,真正的);
                $('#btnchkout')丙(禁用,真正的);
                $('#btnchkin')丙(禁用,假);
            < /文字和GT;
        }
    });
< / SCRIPT>
<按钮ID =btnchkinVALUE =检入类型=提交名称=行动/>
<输入类型=提交ID =btntaskNAME =行动值=PersonalTask​​/>
<输入类型=提交ID =btnchkoutNAME =行动值=结帐/>

下面是您的文章控制器的方法:

  [HttpPost]
公众的ActionResult指数()
{
    ViewBag.IsCheckedIn = TRUE;
    返回查看();
}

请让我知道,如果这是你想要的。

Hello Friends,
please help me i am new in MVC Dot net, and i am try to insert label value on database i have a two labels first for IP address and Second for Current running time and three submit buttons checkin, checkout and going for personal task. on page load checkout and personal task buttons are hidden, only show 2 labels and check in button.
when i am clicking on checkin button both labels value stored in database ms sql2008 . and automatically checkout and personal task button should be enabled and check in button should be disabled.
when i am doing this task with jquery or java script on click event then my insertion task on controller not working only jquery worked.

please help me how i can calling client side click event with html submit button..

my code is: on view -->

 <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" />

on script tag -->

 $("#btnchkin").click(function () {

    alert("a");
    //  $('#btnchkin').prop('disabled', true);
    $('#btntask').prop('disabled', false);
    $('#btnchkout').prop('disabled', false);
    $('#btnchkin').prop('disabled', true);

    //alert("b");
});

and controller-->

[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();
}

解决方案

Here is your controller method:

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

Here is your 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" />

Here is your post controller method:

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

Please let me know if this is what you wanted.

这篇关于如何调用HTML客户端点击MVC中提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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