我試圖通過單擊我的視圖中的鏈接來降低用戶的角色。將字符串傳遞給控制器/查看動作
當我點擊鏈接時,它沒有進入動作,但它只是給出了404錯誤,並且鏈接了未找到的資源和我試圖傳遞給動作的字符串(稱爲「stringparameter 「)
在這種情況下,鏈接/管理/禁止/ stringparameter
我想我沒有使用正確的過載,因此可能有人幫助我嗎? 由於
這是AdminController
[HttpPost]
public ActionResult Disable(string id)
{
Role rol = new UserRepository().GetRole("Disabled");
new UserRepository().UpdateUser(id,rol.RoleId);
return RedirectToAction("Users");
}
這個動作是視圖模型
public class UserSuperUserPM
{
public UserClass User { get; set; }
public List<UserClass> Users { get; set; }
public UserClass SuperUser { get; set; }
public List<UserClass> SuperUsers { get; set; }
public UserClass Disabled { get; set; }
public List<UserClass> Disableds { get; set; }
public UserClass Inactive { get; set; }
public List<UserClass> Inactives { get; set; }
}
這是UserClass的
public class UserClass
{
public string UserId { get; set; }
public string Username { get; set; }
public string Role { get; set; }
}
,這是圖(1在視圖中的4個類似的桌子)
@foreach (var item in Model.Users)
{
<tr>
<td class="col-md-4">
@Html.DisplayFor(modelItem => item.Username, Model.Users)
</td>
<td class="col-md-4">
@Html.DisplayFor(modelItem => item.Role, Model.Users)
</td>
<td calss="col-md-4">
--------Commented attempted links(none of them work correct)
@*@Html.ActionLink("Disable", "Disable", new { Controller = "Admin", action = "Disable", id = item.UserId })*@
@*<a href="~/Controllers/AdminController/[email protected]">Disable</a>*@
@*@Html.ActionLink("Disable","Admin", new { id = item.UserId },null)*@
@*@Html.ActionLink("Disable", "Disable","Admin", item.UserId)*@
-------original attempted link
@Html.ActionLink("Disable", "Disable", new { id = item.UserId})
</td>
</tr>
}
你的控制器的呼叫接入要求POST操作,不是GET。 –