【发布时间】:2010-09-27 10:36:43
【问题描述】:
我觉得我对这个太“网络表单”了,但我还是会问。我在 ASP.NET MVC 项目中有一个表单,上面有一些输入字段和两个按钮。一个按钮用于“过滤”其中一个列表框。另一个用于提交表单。我的视图看起来像这样:
<%using (Html.BeginForm())
{%>
<%=Html.TextBox("SearchItems") %>
<input type="submit" name="Command" value="Find" />
<%=Html.ListBox("SelectedItems", new MultiSelectList(model.AvailableItems,"Id", "Name", model.SelectedItems))%>
//Some other form fields.
<input type="submit" name="Command" value="Send" />
<%} %>
我的操作看起来像这样:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index([Bind(Prefix = "")]SendMessageRequest model)
{
if (model.Command == "Find")
return SearchItems(model);
if (model.Command == "Send")
return Send(model);
throw new Exception("Invalid command.");
}
这很有效——控制器根据被点击的按钮选择正确的动作。但是,它并不理想,因为输入按钮的值也是显示的文本。如果我想翻译这个应用程序,那么操作就会中断。为了解决这个问题,我可以使用
因为这是针对 Pocket IE 的,所以我对 JavaScript 的功能也很有限。 Ajax 已经出局,但我可以从按钮的 onClick 中设置一个隐藏字段。
那么,我的问题是,在 MVC 视图上允许单个表单具有多个按钮的最佳方式是什么?或者,我应该以某种方式将我的观点分解为多种形式吗?
【问题讨论】:
标签: asp.net html asp.net-mvc