在MVC的JavaScript数据库操作 [英] database operation on javascript in MVC
本文介绍了在MVC的JavaScript数据库操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的一个MVC项目。我有我的看法是调用JavaScript函数打印数据的按钮。 code是如下:
I am working on a mvc project. I have a button in my view which is calling a Javascript function to print the data. Code is as follows:
<input type="button" class="btn_image" style="padding-top: 22px;" onclick="PrintDiv();"
value="Print token" />
<head>
<script type="text/javascript">
function PrintDiv() {
var divToPrint = document.getElementById('printableArea');
var popupWin = window.open('', '_blank', 'width=300,height=300');
popupWin.document.open();
popupWin.document.write('<html><body onload="window.print()">' + printableArea.innerHTML + '</html>');
popupWin.document.close();
}
</script>
</head>
现在我想更新数据库记录这个记录已经打印了。我怎样才能做到这一点?我可以执行存储在Javascript程序?
Now I want to update record in database that this record has been printed. How can I do this? May I execute stored procedure in Javascript?
推荐答案
您可以拨打使用Jquery AJAX从客户端在控制器的ActionResult。
function PrintDiv() {
var divToPrint = document.getElementById('printableArea');
var popupWin = window.open('', '_blank', 'width=300,height=300');
popupWin.document.open();
popupWin.document.write('<html><body onload="window.print()">' + printableArea.innerHTML + '</html>');
popupWin.document.close();
UpdateDb();
}
function UpdateDb();
{
$.ajax({
type: 'POST',
url: "@Url.Content("/Contrller/ActionResult/")",
data : {
parameter1:value1,
parameter1: value2
},
dataType: datatype,
success:function(result)
{
//Any thing needed to be done on success
}
});
}
现在写你的逻辑在你的的ActionResult
更新分贝控制器
。
Now write your logic to update Db in your Actionresult
in Controller
.
希望它帮助。
这篇关于在MVC的JavaScript数据库操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文