你好朋友,
请帮助我,我是MVC Dot net的新手,我尝试在数据库上插入标签值我首先有两个标签用于IP地址,第二个用于当前运行时间和三个提交按钮签入,结帐和个人任务。
页面加载结帐和个人任务按钮被隐藏,只显示2个标签和登记按钮
当我点击签入按钮时,两个标签值都存储在数据库ms sql2008中。并应启用自动结账和个人任务按钮,并禁用登记按钮
当我在点击事件上使用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" />
脚本标签上的- &gt;
$("#btnchkin").click(function () {
alert("a");
// $('#btnchkin').prop('disabled', true);
$('#btntask').prop('disabled', false);
$('#btnchkout').prop('disabled', false);
$('#btnchkin').prop('disabled', true);
//alert("b");
});
和控制器 - &gt;
[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();
}
答案 0 :(得分:0)
这是你的控制器方法:
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();
}
如果这是你想要的,请告诉我。