我有這個在我的控制器調用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
上述問題的答案似乎也回答了這個問題。也許我錯了...... :) –