使用 AJAX 的呼叫控制器
call controller using ajax
嘿,我想使用 ajax 调用控制器操作。 但它给出了一个错误。"找不到资源"。JavaScript 函数调用成功 控制器操作未调用
这是我的视图代码:
<a class="btn btn-primary" onclick="EditUser('Delete', 'Users', '@Model.Items.ElementAt(i).ID');">Link</a>
function EditUser(action, controller, id)
{
alert(action);
alert(controller);
alert(id);
$.ajax({
type: "POST",
url: '@Url.Action("Edit", "Users")',
data: "{ id: '" + id + "'}",
success: function (response) {
if (response.d != '1') {
alert('Not Saved!');
}
},
error: function (response) {
if (response.responseText != "") {
alert(response.responseText);
alert("Some thing wrong..");
}
}
});
}
这是我的控制器操作。
public override ActionResult Edit(int id = 0)
{
int a = id;
return View("Edit", DTO);
}
<div id='Sample'></div>
Modify your Ajax function as below.
$.ajax({
type: "POST",
url: '@Url.Action("Edit", "Users")',
data: { id: id },
success: function (response) {
$('#Sample').html(response);
},
error: function (response) {
if (response.responseText != "") {
alert(response.responseText);
alert("Some thing wrong..");
}
}
});
[HttpPost]
public override ActionResult Edit(int id = 0)
{
int a = id;
return PartialView("Edit",dto);
}
如果要将 Ajax 类型指定为 post,请确保添加
[维基邮报]控制器操作中的属性。
相关文章:
- 使用 AJAX 的呼叫控制器
- 无法更改呼叫另一个控制器
- 在控制台中隐藏AJAX控制器调用
- MVC:OnDropDownChange呼叫控制器
- 在控制台中列出正在运行的控制器实例及其 this 变量
- 如何使用 ExtJS 4 中控制器的控制方法更改范围
- $stateprovider控制器中的呼叫服务
- 角度方法在服务呼叫后未在控制器中触发
- 呼叫控制器's方法
- 路由加载时运行成员控制器函数以设置控制复选框的属性
- 使用单个控制器控制多个html5音轨
- 控制控制器显示的角度
- 从Angular控制器控制SoundCloud js sdk
- 访问控制导致不同呼叫出现问题
- 为什么从AngularJS'内部加载时谷歌图不工作;s控制器.浏览器变白,控制台中没有任何错误
- 如何在angular控制器中控制服务器响应
- Angular控制器不控制日志数据.然而,Service正在传递数据
- Vimeo内嵌视频自定义控制器(全屏和音量控制)在media element js中不起作用
- 插入部件时无需呼叫把手助手或带插座的控制器
- 未调用控制器.控制台上没有错误