使用javaScript将DataView传递给控制器
我试图让视图与控制器通信,以使用javascript、mvc和Asp.Net更新值(数据库) 这是我的看法使用javaScript将DataView传递给控制器,javascript,asp.net,asp.net-mvc,viewdata,Javascript,Asp.net,Asp.net Mvc,Viewdata,我试图让视图与控制器通信,以使用javascript、mvc和Asp.Net更新值(数据库) 这是我的看法 function updateRejectType() { $("#btnvalider").click(function () var IdRTDoc = <%: ViewData["IdRTDoc"] %> ; var strTypeDocument=<%:ViewData["RejectedTypesList"]
function updateRejectType() {
$("#btnvalider").click(function ()
var IdRTDoc = <%: ViewData["IdRTDoc"] %> ;
var strTypeDocument=<%:ViewData["RejectedTypesList"] %>;
var strLabel= <%: ViewData["strLabel"] %> ;
$.ajax({
type: "GET",
url: '<%= Url.Action("UpdateRejectedType", "RejectedTypes") %>',
data: "IdRTDoc=" + IdRTDoc +"DocumentType"+ strTypeDocument + "Label" + strLabel,
processData: false,
cache: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
complete: function () {
alert("updated");
},
success: function () {
error: FailureFunction
});
success: function (result, request) {
alert("Mis à jour avec succès");
SuccessValider();
},
failure: FailureFunctionUpdate
});
}
function SuccessValider(){
window.open('../Home/About', '_parent');
}
function FailureFunctionUpdate() {
alert("Problème survenu dans update !");
}
</script>
当我点击按钮时,什么都没有发生。我能做些什么使它工作呢?因为你的按钮有
onclick=“updateRejectType()”
属性,你不需要用$(“#btnvalider”)绑定点击事件。点击(函数()
。您还错过了数据
选项中的&
和=
。请按如下所示更改脚本
<script type="text/javascript">
function updateRejectType() {
var IdRTDoc = <%: ViewData["IdRTDoc"] %> ;
var strTypeDocument=<%:ViewData["RejectedTypesList"] %>;
var strLabel= <%: ViewData["strLabel"] %> ;
$.ajax({
type: "GET",
url: '<%= Url.Action("UpdateRejectedType", "RejectedTypes") %>',
data: "IdRTDoc=" + IdRTDoc +"&DocumentType="+ strTypeDocument + "&Label=" + strLabel,
processData: false,
cache: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
complete: function () {
alert("updated");
},
success: function (result, request) {
alert("Mis à jour avec succès");
SuccessValider();
},
error: FailureFunctionUpdate
});
}
function SuccessValider(){
window.open('../Home/About', '_parent');
}
function FailureFunctionUpdate() {
alert("Problème survenu dans update !");
}
</script>
函数updateRejectType(){
var idrtoc=;
var strTypeDocument=;
var strLabel=;
$.ajax({
键入:“获取”,
url:“”,
数据:“idrdoc=“+idrdoc+”&DocumentType=“+strTypeDocument+”&Label=“+strLabel,
processData:false,
cache:false,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
完成:函数(){
警报(“更新”);
},
成功:功能(结果、请求){
警惕(“成功的时机”);
成功者();
},
错误:FailureFunctionUpdate
});
}
函数SuccessValider(){
window.open('../Home/About','u parent');
}
函数失败函数更新(){
警报(“survenu dans更新问题!”);
}
尝试以下方法传递数据:
data: {IdRTDoc: IdRTDoc, DocumentType: strTypeDocument, Label: strLabel},
UpdateRejectedType
真的被点击了吗?很抱歉,我没有工作,我认为错误在函数中,但我看不到它
<script type="text/javascript">
function updateRejectType() {
var IdRTDoc = <%: ViewData["IdRTDoc"] %> ;
var strTypeDocument=<%:ViewData["RejectedTypesList"] %>;
var strLabel= <%: ViewData["strLabel"] %> ;
$.ajax({
type: "GET",
url: '<%= Url.Action("UpdateRejectedType", "RejectedTypes") %>',
data: "IdRTDoc=" + IdRTDoc +"&DocumentType="+ strTypeDocument + "&Label=" + strLabel,
processData: false,
cache: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
complete: function () {
alert("updated");
},
success: function (result, request) {
alert("Mis à jour avec succès");
SuccessValider();
},
error: FailureFunctionUpdate
});
}
function SuccessValider(){
window.open('../Home/About', '_parent');
}
function FailureFunctionUpdate() {
alert("Problème survenu dans update !");
}
</script>
data: {IdRTDoc: IdRTDoc, DocumentType: strTypeDocument, Label: strLabel},