【问题标题】:ID auto added in the POST urlPOST url 中自动添加的 ID
【发布时间】:2018-07-31 15:59:17
【问题描述】:

我的应用程序中有一个编辑视图。这是我的Razor syntax POSTingform

@using (Html.BeginForm("edit", "person", FormMethod.Post))
{
}

运行我的应用程序后,检查浏览器中的标记,生成markup

<form method="post" action="/person/edit/1">

我希望 url 在另一个 POST 操作中成为 "/person/edit"

这是我在Controller 中的action 方法

[Route("edit/{person_id}")]
public IActionResult edit(long person_id)
{
    //some stuffs
    return View();
}

【问题讨论】:

  • 你的问题???
  • @MRebati 问题明确指出 ID 是自动添加的。我需要“/person/edit”格式的网址
  • 那就不要使用剃须刀了。它只是创建首选的 HTML 代码。所以只需编写所需的 HTML。
  • @MRebati 这样做不会验证防伪令牌。还是这样?
  • 您在生成的 HTML 表单中是否发现任何异常?如果不是,那么它与剃须刀发电机无关。

标签: razor model-view-controller asp.net-core-2.0


【解决方案1】:

在返回View 之前在action 中添加RouteData.Values.Remove("person_id"); 对我有用。 https://stackoverflow.com/questions/6020253/calling-html-beginform-and-specifying-action

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-27
    • 2014-08-03
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    • 2012-07-27
    • 2015-04-27
    • 2021-02-14
    相关资源
    最近更新 更多