我正在编码我的admin可以delete
和edit
一个用户的帐户。我能够基于Id Account
获得该帐户,但当我点击提交edit
时,我的页面自动返回到Edit
页面。代码和图像如下:
@model Megatron.Models.ApplicationUser
@{
ViewData["Title"] = "Edit Account";
}
<h1>Edit Account</h1>
<hr />
@Html.HiddenFor(u => u.Id)
<div class="row">
<div class="col-md-4">
<form asp-action="EditAcount">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="FullName" class="control-label"></label>
<input asp-for="FullName" class="form-control" />
<span asp-validation-for="FullName" class="text-danger"></span>
</div>
@*<div class="form-group">
<label asp-for="Email" class="control-label"></label>
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>*@
@*<div class="form-group">
<label asp-for="PhoneNumber" class="control-label"></label>
<input asp-for="PhoneNumber" class="form-control" />
<span asp-validation-for="PhoneNumber" class="text-danger"></span>
</div>*@
<div class="form-group row">
<div class="col-md-5 offset-md-2">
<button type="submit" class="btn btn-primary form-control">Edit</button>
</div>
</div>
</form>
</div>
</div>
<div>
<a asp-action="Index">Back to List</a>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}
我觉得你的表单asp-action
字段有一个错别字。
应该是:
@Html.HiddenFor(u => u.Id)
<div class="row">
<div class="col-md-4">
<form asp-action="EditAccount">
...
现在,当你点击Edit
按钮,它应该正确地转到正确的HttpPostEditAccount
方法。