我有一个执行以下操作的控制器
[HttpPost("training/create", Name="Create")]
public async Task<IActionResult> Create(CreateTrainingCommand command){
// doing stuff ...
}
[HttpGet("training/createblankform", Name="CreateBlankForm")]
public async Task<IActionResult> CreateBlankForm(CreateBlankFormQuery command){
// doing stuff ...
}
[HttpPost("training/createblankform", Name="CreateBlankForm")]
public async Task<IActionResult> CreateBlankForm(CreateBlankFormCommand command){
// doing stuff ...
}
在StartUp.cs文件中,我正在使用app.UseMvcWithDefaultRoute() and I have loaded a View that is loaded using the
CreateBlankForm GET`操作。
该视图包含应提交给CreateBlankForm
POST
动作的表单,但Create
POST
动作受到了打击。
我尝试以几种不同的方式配置表单;
<form class="form-horizontal" role="form" contenteditable="" asp-controller="Training" asp-action="CreateBlankForm" method="post">
...
<input id="submit" type="button" value="Create" />
</form>
和
<form class="form-horizontal" role="form" contenteditable="" asp-route="CreateBlankTrainingForm" method="post">
...
<input id="submit" type="button" value="Create" />
</form>
和
<form class="form-horizontal" role="form" action="/training/createblankform" method="post">
...
<input id="submit" type="button" value="Create" />
</form>
但是所有这些仍然击中了CreateBlankForm
POST
动作。为什么这会打错控制器?
答案 0 :(得分:1)
是否有任何JavaScript事件正在处理submit
表单操作?
答案 1 :(得分:0)
尝试更改
<input id="submit" type="button" value="Create" />
到
<input id="submit" type="submit" value="Create" />
以及您指定的错误操作名称 应该是
action="createblankform"
不是
action="/training/createblankform"
如果您有任何问题,请告诉我