【发布时间】:2018-05-12 19:00:06
【问题描述】:
主要问题是当我按下按钮时,控制器中的方法没有被调用。 我在 MyController 的索引视图中有这个:
@using (Html.BeginForm())
{
@* .... *@
<form action="DoSomethingAction" method="post">
<input type="text" id="IdString" name="IdString" placeholder="Enter id"/>
<input id="Submit1" name="Submit1" type="submit" value="DoSomething1" />
<input id="Submit2" name="Submit2" type="submit" value="DoSomething2" />
</form>
@* ..... *@
}
在 MyController 我有 DoSomethingAction 方法。我想调用此方法并在按下按钮时能够看到 IdString:DoSomething1 或 DoSomething2。这是来自控制器的 DoSomethingAction 方法:
public ActionResult DoSomethingAction()
{
string id= Request.Form["IdString"];
//string button=...
// ...
}
当我为 DoSomethingAction 方法设置断点时,我发现它从未被调用过。 我试图为这个方法添加 [Httppost] 属性,但它并没有解决我的问题。
我做错了什么? 之后,如何在 DoSomethingAction 方法中查看按下了哪个按钮?
【问题讨论】:
-
您的嵌套表单是无效的 html 且不受支持
-
修复无效的嵌套表单,接受答案,然后返回新问题,也许是关于您遇到的新问题。尽量把问题集中在一个问题上,你可能会得到更好的回应和进步。
标签: c# asp.net-mvc