【问题标题】:Submit Edit automatically returns to the Edit page?提交编辑自动返回编辑页面?
【发布时间】:2021-05-28 13:30:30
【问题描述】:

我正在编写我的管理员可以deleteedit 用户帐户。我能够根据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.net-mvc asp.net-core dependency-injection asp.net-core-mvc repository-pattern


    【解决方案1】:

    我认为您的表单asp-action 字段中有错字。

    应该是:

    @Html.HiddenFor(u => u.Id)
    <div class="row">
        <div class="col-md-4">
            <form asp-action="EditAccount">
            ...
    

    现在,当您单击 Edit 按钮时,它应该正确地转到正确的 HttpPost EditAccount 方法。

    【讨论】:

      猜你喜欢
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多