我有这个在我的控制器调用MVC控制器功能:C#如何使用JavaScript或jQuery的
$('#btnDelete').click(function (e) {
});
如何从js文件调用控制器函数?
我有这个在我的控制器调用MVC控制器功能:C#如何使用JavaScript或jQuery的
$('#btnDelete').click(function (e) {
});
如何从js文件调用控制器函数?
$.post("Controller/CreateUser", dataToPost)
.done(function(response, status, jqxhr){
// this is the "success" callback
})
.fail(function(jqxhr, status, error){
// this is the ""error"" callback
});
或
var data = {
username: $('#username').val().trim(),
password: $('#password').val()
};
$.ajax({
type: "POST",
url: "Controller/CreateUser",
content: "application/json;",
dataType: "json",
data: JSON.stringify(data),
success: function(d) {
},
error: function (xhr, textStatus, errorThrown) {
}
});
PS:根据UserViewModel属性构成的数据对象。
我打错误:POST本地主机:56110 /用户/控制器/ DeleteUser – Enix
我离开控制器,因为我不知道你的控制器的名称。只需将其删除并放置正确的控制器名称 –
里面的按钮点击,执行Ajax请求
$('#btnDelete').click(function (e) {
$.ajax({
type: "POST",
url: 'controller/DeleteUser',
dataType: "json",
success: function(data){
//html content
},
});
}
这很容易访问使用AJAX POST方法的任何控制器的方法。
正如我在这里按照选定的国家使用 “RegionesController”方法名“GETSTATES”也是在这里,我路过 CountryId获得国家按本ID获得的状态。
EX:
function GetStates() {
$.ajax({
type: "POST",
async: false,
url: abp.appPath + 'Regiones/GetStates?CountryId=' + $("#ddlCountry").val(),
success: function (result) {
//return data or object
},
error: function (err) {
abp.notify.info(err.statusText);
}
});
}
伟大的工作Arpit ..................... –
包括'@ Html.AntiForgeryToken()'在您发布 –
@PrashanthBenny形式如何,这是一个特定的防伪问题的重复,如果OP似乎有不知道如何首先发布到控制器,或者是否指定了正在使用的表单?这个问题是如何成为这个问题的?据我所知,我确定它是某种类型的复制品,但不是这个问题的复制品。 - 对不起,我错过了什么。 – Nope
上述问题的答案似乎也回答了这个问题。也许我错了...... :) –