【发布时间】:2015-08-21 07:04:21
【问题描述】:
所以我有下一个问题。我只想刷新部分视图,但它不起作用。我尝试在 onclick 上执行两个操作,但我需要按 3 次按钮才能刷新。
这是我的党派观点
<table>
<tr>
<td>Id</td>
<td>UserName</td>
<td>FirstName</td>
<td>LastName</td>
<td>Email</td>
<td>Rolul</td>
<td></td>
</tr>
@foreach (var item in Model.users)
{
<tr>
<td>@item.UserID</td>
<td>@item.UserName</td>
<td>@item.FirstName</td>
<td>@item.LastName</td>
<td>@item.Email</td>
<td>@item.RoleId</td>
@if (item.RoleId == 2)
{
<td><input type="button" value="MakeAdmin" onclick="makeUserAdmin(@item.UserID);"/></td>
}
@if(item.RoleId==1)
{
<td><input type="button" value="RemoveAdmin" onclick="removeUserAdmin(@item.UserID);ShowTable('@Url.Action("UserTableView","User")" /></td>
}
@if (item.RoleId == 3)
{
<td><input type="button" disabled value="SuperAdmin" /></td>
}
</tr>
}
</table>
这是我的 js
$(document).ready(function () {
function makeUserAdmin(userId) {
$.ajax({
type: 'post',
url: '/User/MakeAdmin',
data: JSON.stringify
({
userId: userId
}),
contentType: 'application/json;charset=utf-8',
dataType: 'json',
success: function (data) {
if (data.Succes) {
alert("..");
}
else {
alert(data.Errors[0]);
}
}
});
}
function removeUserAdmin(userId) {
$.ajax({
type: 'post',
url: '/User/RemoveUserAdmin',
data: JSON.stringify
({
userId: userId
}),
contentType: 'application/json;charset=utf-8',
dataType: 'json',
success: function (data) {
if (data.Succes) {
alert("...");
}
else {
alert(data.Errors[0]);
}
}
});
}
});
有什么想法吗?
【问题讨论】:
-
为什么你调用
ShowTable两次,同时在html中删除一次,在ajax success中删除一次,你的ShowTable函数在哪里? -
你的
ShowTable函数在哪里? -
已编辑,抱歉,刚刚尝试过,无法正常工作..
-
Showtable 函数在另一个 js 文件中。想法是,当我在 html 中调用函数时,我需要按 3 次按钮才能刷新
-
那么到底发生了什么?你能详细说明一下功能吗?你的问题不清楚!
标签: javascript jquery .net asp.net-mvc model-view-controller